Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add modal example #30406

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/rn-tester/js/components/ExamplePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const styles = StyleSheet.create({
examplesContainer: {
width: ScreenWidth,
flexGrow: 1,
flex: 1,
},
description: {
marginVertical: 8,
Expand Down
80 changes: 72 additions & 8 deletions packages/rn-tester/js/examples/Modal/ModalExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const {
Text,
TouchableHighlight,
View,
ScrollView,
} = require('react-native');

const Item = Picker.Item;
Expand Down Expand Up @@ -78,9 +79,12 @@ class ModalExample extends React.Component<{...}, $FlowFixMeState> {
animationType: 'none',
modalVisible: false,
transparent: false,
hardwareAccelerated: false,
statusBarTranslucent: false,
presentationStyle: 'fullScreen',
selectedSupportedOrientation: '0',
currentOrientation: 'unknown',
action: '',
};

_setModalVisible = visible => {
Expand All @@ -95,10 +99,39 @@ class ModalExample extends React.Component<{...}, $FlowFixMeState> {
this.setState({transparent: !this.state.transparent});
};

_toggleHardwareAccelerated = () => {
this.setState({hardwareAccelerated: !this.state.hardwareAccelerated});
};

_toggleStatusBarTranslucent = () => {
this.setState({statusBarTranslucent: !this.state.statusBarTranslucent});
};

renderSwitch() {
if (Platform.isTV) {
return null;
}
if (Platform.OS === 'android') {
return (
<>
<Text style={styles.rowTitle}>Hardware Accelerated</Text>
<Switch
value={this.state.hardwareAccelerated}
onValueChange={this._toggleHardwareAccelerated}
/>
<Text style={styles.rowTitle}>Status Bar Translucent</Text>
<Switch
value={this.state.statusBarTranslucent}
onValueChange={this._toggleStatusBarTranslucent}
/>
<Text style={styles.rowTitle}>Transparent</Text>
<Switch
value={this.state.transparent}
onValueChange={this._toggleTransparent}
/>
</>
);
}
return (
<Switch
value={this.state.transparent}
Expand All @@ -121,11 +154,13 @@ class ModalExample extends React.Component<{...}, $FlowFixMeState> {
};

return (
<View>
<ScrollView contentContainerStyle={styles.ScrollView}>
<Modal
animationType={this.state.animationType}
presentationStyle={this.state.presentationStyle}
transparent={this.state.transparent}
hardwareAccelerated={this.state.hardwareAccelerated}
statusBarTranslucent={this.state.statusBarTranslucent}
visible={this.state.modalVisible}
onRequestClose={() => this._setModalVisible(false)}
supportedOrientations={
Expand All @@ -135,7 +170,13 @@ class ModalExample extends React.Component<{...}, $FlowFixMeState> {
}
onOrientationChange={evt =>
this.setState({currentOrientation: evt.nativeEvent.orientation})
}>
}
onDismiss={() => {
if (this.state.action === 'onDismiss') alert(this.state.action);
}}
onShow={() => {
if (this.state.action === 'onShow') alert(this.state.action);
}}>
<View style={[styles.container, modalBackgroundStyle]}>
<View
style={[styles.innerContainer, innerContainerTransparentStyle]}>
Expand Down Expand Up @@ -181,15 +222,12 @@ class ModalExample extends React.Component<{...}, $FlowFixMeState> {
</Button>
</View>

<View style={styles.row}>
<Text style={styles.rowTitle}>Transparent</Text>
{this.renderSwitch()}
</View>
<View style={styles.row}>{this.renderSwitch()}</View>
{this.renderPickers()}
<Button onPress={this._setModalVisible.bind(this, true)}>
Present
</Button>
</View>
</ScrollView>
);
}
renderPickers() {
Expand Down Expand Up @@ -219,7 +257,7 @@ class ModalExample extends React.Component<{...}, $FlowFixMeState> {
<Picker
selectedValue={this.state.selectedSupportedOrientation}
onValueChange={(_, i) =>
this.setState({selectedSupportedOrientation: i})
this.setState({selectedSupportedOrientation: i.toString()})
}
itemStyle={styles.pickerItem}>
<Item label="Portrait" value={'0'} />
Expand All @@ -230,6 +268,28 @@ class ModalExample extends React.Component<{...}, $FlowFixMeState> {
<Item label="Default supportedOrientations" value={'5'} />
</Picker>
</View>

<View>
<Text style={styles.rowTitle}>Actions</Text>
{Platform.OS === 'ios' ? (
<Picker
selectedValue={this.state.action}
onValueChange={action => this.setState({action})}
itemStyle={styles.pickerItem}>
<Item label="None" value="" />
<Item label="On Dismiss" value="onDismiss" />
<Item label="On Show" value="onShow" />
</Picker>
) : (
<Picker
selectedValue={this.state.action}
onValueChange={action => this.setState({action})}
itemStyle={styles.pickerItem}>
<Item label="None" value="" />
<Item label="On Show" value="onShow" />
</Picker>
)}
</View>
</View>
);
}
Expand Down Expand Up @@ -282,4 +342,8 @@ const styles = StyleSheet.create({
pickerItem: {
fontSize: 16,
},
ScrollView: {
paddingTop: 10,
paddingBottom: 100,
},
});