Skip to content

Commit 3ec9320

Browse files
committed
Improved example project
1 parent de2e689 commit 3ec9320

File tree

5 files changed

+55
-19
lines changed

5 files changed

+55
-19
lines changed

example/ios/example.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@
501501
PRODUCT_NAME = example;
502502
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
503503
SWIFT_VERSION = 5.0;
504+
TARGETED_DEVICE_FAMILY = "1,2";
504505
VERSIONING_SYSTEM = "apple-generic";
505506
};
506507
name = Debug;
@@ -525,6 +526,7 @@
525526
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
526527
PRODUCT_NAME = example;
527528
SWIFT_VERSION = 5.0;
529+
TARGETED_DEVICE_FAMILY = "1,2";
528530
VERSIONING_SYSTEM = "apple-generic";
529531
};
530532
name = Release;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

example/src/App.tsx

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ import {
1111
TextInput,
1212
View,
1313
Button,
14+
SafeAreaView,
1415
StatusBarStyle,
16+
useColorScheme,
17+
ScrollView,
1518
} from 'react-native';
1619
import {openLink, tryDeepLinking} from './utils';
1720
import {InAppBrowser} from 'react-native-inappbrowser-reborn';
21+
import {Colors} from 'react-native/Libraries/NewAppScreen';
1822

1923
const instructions = Platform.select({
2024
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
@@ -35,26 +39,40 @@ const App = () => {
3539
await openLink(url, statusBarStyle);
3640
}, [url, statusBarStyle]);
3741

42+
const isDarkMode = useColorScheme() === 'dark';
43+
44+
const backgroundStyle = {
45+
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
46+
flex: 1,
47+
height: '100%',
48+
};
49+
3850
return (
39-
<View style={styles.container}>
51+
<SafeAreaView style={backgroundStyle}>
4052
<StatusBar barStyle={statusBarStyle} />
41-
<Text style={styles.welcome}>
42-
{'Welcome InAppBrowser\nfor React Native!'}
43-
</Text>
44-
<Text style={styles.instructions}>Type the url</Text>
45-
<TextInput
46-
style={styles.urlInput}
47-
onChangeText={text => setUrl(text)}
48-
value={url}
49-
/>
50-
<View style={styles.openButton}>
51-
<Button title="Open link" onPress={onOpenLink} />
52-
</View>
53-
<View style={styles.openButton}>
54-
<Button title="Try deep linking" onPress={tryDeepLinking} />
55-
</View>
56-
<Text style={styles.instructions}>{instructions}</Text>
57-
</View>
53+
<ScrollView
54+
contentInsetAdjustmentBehavior="automatic"
55+
contentContainerStyle={backgroundStyle}>
56+
<View style={styles.container}>
57+
<Text style={styles.welcome}>
58+
{'Welcome InAppBrowser\nfor React Native!'}
59+
</Text>
60+
<Text style={styles.instructions}>Type the url</Text>
61+
<TextInput
62+
style={styles.urlInput}
63+
onChangeText={text => setUrl(text)}
64+
value={url}
65+
/>
66+
<View style={styles.openButton}>
67+
<Button title="Open link" onPress={onOpenLink} />
68+
</View>
69+
<View style={styles.openButton}>
70+
<Button title="Try deep linking" onPress={tryDeepLinking} />
71+
</View>
72+
<Text style={styles.instructions}>{instructions}</Text>
73+
</View>
74+
</ScrollView>
75+
</SafeAreaView>
5876
);
5977
};
6078

@@ -65,6 +83,7 @@ const styles = StyleSheet.create({
6583
alignItems: 'center',
6684
backgroundColor: '#F5FCFF',
6785
padding: 30,
86+
height: '100%',
6887
},
6988
welcome: {
7089
fontSize: 20,

example/src/utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
StatusBar,
55
Linking,
66
StatusBarStyle,
7+
Dimensions,
78
} from 'react-native';
89
import {InAppBrowser} from 'react-native-inappbrowser-reborn';
910

@@ -16,6 +17,7 @@ export const openLink = async (
1617
animated = true,
1718
) => {
1819
try {
20+
const {width, height} = Dimensions.get('window');
1921
if (await InAppBrowser.isAvailable()) {
2022
// A delay to change the StatusBar when the browser is opened
2123
const delay = animated && Platform.OS === 'ios' ? 400 : 0;
@@ -27,10 +29,14 @@ export const openLink = async (
2729
preferredControlTintColor: 'white',
2830
readerMode: true,
2931
animated,
30-
modalPresentationStyle: 'fullScreen',
32+
modalPresentationStyle: 'formSheet',
3133
modalTransitionStyle: 'flipHorizontal',
3234
modalEnabled: true,
3335
enableBarCollapsing: true,
36+
formSheetPreferredContentSize: {
37+
width: width - width / 6,
38+
height: height - height / 6,
39+
},
3440
// Android Properties
3541
showTitle: true,
3642
toolbarColor: '#6200EE',

example/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
"extends": "@tsconfig/react-native/tsconfig.json", /* Recommended React Native TSConfig base */
44
"compilerOptions": {
5+
"jsx": "react",
56
/* Visit https://aka.ms/tsconfig.json to read more about this file */
67

78
/* Completeness */

0 commit comments

Comments
 (0)