/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow strict-local
*/
'use strict';
const React = require('react');
const {
Modal,
Picker,
Platform,
StyleSheet,
Switch,
Text,
TouchableHighlight,
View,
ScrollView,
} = require('react-native');
const Item = Picker.Item;
exports.displayName = (undefined: ?string);
exports.framework = 'React';
exports.title = 'Modal';
exports.category = 'UI';
exports.documentationURL = 'https://reactnative.dev/docs/modal';
exports.description = 'Component for presenting modal views.';
class Button extends React.Component<$FlowFixMeProps, $FlowFixMeState> {
state = {
active: false,
};
_onHighlight = () => {
this.setState({active: true});
};
_onUnhighlight = () => {
this.setState({active: false});
};
render() {
const colorStyle = {
color: this.state.active ? '#fff' : '#000',
};
return (
{this.props.children}
);
}
}
const supportedOrientationsPickerValues = [
['portrait'],
['landscape'],
['landscape-left'],
['portrait', 'landscape-right'],
['portrait', 'landscape'],
[],
];
class ModalExample extends React.Component<{...}, $FlowFixMeState> {
state = {
animationType: 'none',
modalVisible: false,
transparent: false,
hardwareAccelerated: false,
statusBarTranslucent: false,
presentationStyle: 'fullScreen',
selectedSupportedOrientation: '0',
currentOrientation: 'unknown',
action: '',
};
_setModalVisible = visible => {
this.setState({modalVisible: visible});
};
_setAnimationType = type => {
this.setState({animationType: type});
};
_toggleTransparent = () => {
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 (
<>
Hardware Accelerated
Status Bar Translucent
Transparent
>
);
}
return (
);
}
render() {
const modalBackgroundStyle = {
backgroundColor: this.state.transparent
? 'rgba(0, 0, 0, 0.5)'
: '#f5fcff',
};
const innerContainerTransparentStyle = this.state.transparent
? {backgroundColor: '#fff', padding: 20}
: null;
const activeButtonStyle = {
backgroundColor: '#ddd',
};
return (
this._setModalVisible(false)}
supportedOrientations={
supportedOrientationsPickerValues[
Number(this.state.selectedSupportedOrientation)
]
}
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);
}}>
This modal was presented{' '}
{this.state.animationType === 'none' ? 'without' : 'with'}{' '}
animation.
It is currently displayed in {this.state.currentOrientation}{' '}
mode.
Animation Type
{this.renderSwitch()}
{this.renderPickers()}
);
}
renderPickers() {
if (Platform.isTV) {
return null;
}
return (
Presentation style
this.setState({presentationStyle})
}
itemStyle={styles.pickerItem}>
Supported orientations
this.setState({selectedSupportedOrientation: i.toString()})
}
itemStyle={styles.pickerItem}>
Actions
{Platform.OS === 'ios' ? (
this.setState({action})}
itemStyle={styles.pickerItem}>
) : (
this.setState({action})}
itemStyle={styles.pickerItem}>
)}
);
}
}
exports.examples = [
{
title: 'Modal Presentation',
description: 'Modals can be presented with or without animation',
render: (): React.Node => ,
},
];
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
padding: 20,
},
innerContainer: {
borderRadius: 10,
alignItems: 'center',
},
row: {
alignItems: 'center',
flex: 1,
flexDirection: 'row',
marginBottom: 20,
},
rowTitle: {
flex: 1,
fontWeight: 'bold',
},
button: {
borderRadius: 5,
flexGrow: 1,
height: 44,
alignSelf: 'stretch',
justifyContent: 'center',
overflow: 'hidden',
},
buttonText: {
fontSize: 18,
margin: 5,
textAlign: 'center',
},
modalButton: {
marginTop: 10,
},
pickerItem: {
fontSize: 16,
},
ScrollView: {
paddingTop: 10,
paddingBottom: 100,
},
});