Skip to content

Commit 2183fd1

Browse files
authored
feat: add web support (#67)
* feat: add web support * fix: flow error * chore: move typescript typing * fix: fix typing
1 parent 92cf6f0 commit 2183fd1

14 files changed

+9100
-379
lines changed

example/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,7 @@ buck-out/
5757

5858
# CocoaPods
5959
/ios/Pods/
60+
61+
# expo generated files
62+
.expo
63+
web-build

example/App.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import React from 'react';
99
import {StyleSheet, ScrollView, Text, View} from 'react-native';
10-
import SegmentedControlIOS from '@react-native-community/segmented-control';
10+
import SegmentedControl from '@react-native-community/segmented-control';
1111

1212
export default class App extends React.Component<{}, $FlowFixMeState> {
1313
state = {
@@ -21,30 +21,28 @@ export default class App extends React.Component<{}, $FlowFixMeState> {
2121
<ScrollView contentContainerStyle={styles.container}>
2222
<View style={styles.segmentContainer}>
2323
<Text style={styles.text}>Segmented controls can have values</Text>
24-
<SegmentedControlIOS values={['One', 'Two']} />
24+
<SegmentedControl values={['One', 'Two']} />
2525
</View>
2626

2727
<View style={styles.segmentSection}>
28-
<SegmentedControlIOS
29-
values={['One', 'Two', 'Three', 'Four', 'Five']}
30-
/>
28+
<SegmentedControl values={['One', 'Two', 'Three', 'Four', 'Five']} />
3129
</View>
3230

3331
<View style={styles.segmentSection}>
3432
<Text style={styles.text}>
3533
Segmented controls can have pre-selected values
3634
</Text>
37-
<SegmentedControlIOS values={['One', 'Two']} selectedIndex={0} />
35+
<SegmentedControl values={['One', 'Two']} selectedIndex={0} />
3836
</View>
3937

4038
<View style={styles.segmentSection}>
4139
<Text style={styles.text}>Segmented controls can be momentary</Text>
42-
<SegmentedControlIOS values={['One', 'Two']} momentary={true} />
40+
<SegmentedControl values={['One', 'Two']} momentary={true} />
4341
</View>
4442

4543
<View style={styles.segmentSection}>
4644
<Text style={styles.text}>Segmented controls can be disabled</Text>
47-
<SegmentedControlIOS
45+
<SegmentedControl
4846
enabled={false}
4947
values={['One', 'Two']}
5048
selectedIndex={1}
@@ -53,22 +51,24 @@ export default class App extends React.Component<{}, $FlowFixMeState> {
5351

5452
<View style={styles.segmentContainer}>
5553
<Text style={styles.text}>Custom colors can be provided</Text>
56-
<SegmentedControlIOS
54+
<SegmentedControl
5755
tintColor="#ff0000"
5856
values={['One', 'Two', 'Three', 'Four']}
5957
selectedIndex={0}
6058
backgroundColor="#0000ff"
59+
activeTextColor="white"
6160
/>
6261
</View>
6362
<View style={styles.segmentContainer}>
64-
<SegmentedControlIOS
63+
<SegmentedControl
6564
tintColor="#00ff00"
6665
values={['One', 'Two', 'Three']}
6766
selectedIndex={1}
67+
activeTextColor="black"
6868
/>
6969
</View>
7070
<View style={styles.segmentSection}>
71-
<SegmentedControlIOS
71+
<SegmentedControl
7272
textColor="#ff00ff"
7373
values={['One', 'Two']}
7474
selectedIndex={1}
@@ -78,7 +78,7 @@ export default class App extends React.Component<{}, $FlowFixMeState> {
7878
<View>
7979
<Text style={styles.text}>Custom colors can be provided</Text>
8080
<View style={styles.segmentContainer}>
81-
<SegmentedControlIOS
81+
<SegmentedControl
8282
values={this.state.values}
8383
selectedIndex={this.state.selectedIndex}
8484
onChange={this._onChange}

example/app.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
22
"name": "example",
3-
"displayName": "example"
4-
}
3+
"displayName": "example",
4+
"expo": {
5+
"platforms": ["web"]
6+
}
7+
}

example/babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
presets: ['module:metro-react-native-babel-preset'],
2+
presets: ['babel-preset-expo'],
33
};

example/index.web.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Entry point for react-native-web
2+
import App from './App';
3+
import {AppRegistry} from 'react-native';
4+
import {name as appName} from './app.json';
5+
6+
AppRegistry.registerComponent(appName, () => App);
7+
AppRegistry.runApplication(appName, {
8+
rootTag: document.getElementById('root'),
9+
});

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ PODS:
182182
- React-cxxreact (= 0.61.5)
183183
- React-jsi (= 0.61.5)
184184
- React-jsinspector (0.61.5)
185-
- react-native-segmented-control (1.0.2):
185+
- react-native-segmented-control (1.3.0):
186186
- React
187187
- React-RCTActionSheet (0.61.5):
188188
- React-Core/RCTActionSheetHeaders (= 0.61.5)
@@ -326,7 +326,7 @@ SPEC CHECKSUMS:
326326
React-jsi: cb2cd74d7ccf4cffb071a46833613edc79cdf8f7
327327
React-jsiexecutor: d5525f9ed5f782fdbacb64b9b01a43a9323d2386
328328
React-jsinspector: fa0ecc501688c3c4c34f28834a76302233e29dc0
329-
react-native-segmented-control: 2843178bfa06561a328b7f3999d4fb1af315b11b
329+
react-native-segmented-control: 64a281fade11306631dccd3bbeac6e55b5ab362f
330330
React-RCTActionSheet: 600b4d10e3aea0913b5a92256d2719c0cdd26d76
331331
React-RCTAnimation: 791a87558389c80908ed06cc5dfc5e7920dfa360
332332
React-RCTBlob: d89293cc0236d9cb0933d85e430b0bbe81ad1d72

example/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@
55
"scripts": {
66
"android": "react-native run-android",
77
"ios": "react-native run-ios",
8-
"start": "react-native start"
8+
"start": "react-native start",
9+
"web": "expo start --web"
910
},
1011
"dependencies": {
12+
"@react-native-community/segmented-control": "file:../",
13+
"expo": "^37.0.7",
1114
"react": "16.9.0",
15+
"react-dom": "16.9.0",
1216
"react-native": "0.61.5",
13-
"@react-native-community/segmented-control": "file:../"
17+
"react-native-web": "^0.12.2"
1418
},
1519
"devDependencies": {
1620
"@babel/core": "^7.6.2",
1721
"@babel/runtime": "^7.6.2",
18-
"metro-react-native-babel-preset": "^0.56.0"
22+
"babel-preset-expo": "^8.1.0"
1923
},
2024
"jest": {
2125
"preset": "react-native"

0 commit comments

Comments
 (0)