mirror of
https://github.com/status-im/react-native.git
synced 2025-01-10 09:35:48 +00:00
191d278fda
Summary: Currently the Modal component on Android is rendered below the Status Bar, which changes it's color to grey, and in the UIExplorer example the backdrop is just formatted to look the same color. In some scenarios users may want to preserve the color of their status bar and make it look as though the modal is appearing on top. This PR allows for that. This GIF shows current behavior and new behavior with the translucentStatusBar prop set to true. ![](http://g.recordit.co/BSX5g9obRC.gif) I've updated the UIExplorer app to demonstrate and the docs as shown below ![image](https://cloud.githubusercontent.com/assets/4265163/14742854/500e1292-086c-11e6-9275-71808b0cbed7.png) Thanks! Closes https://github.com/facebook/react-native/pull/7157 Differential Revision: D3264497 Pulled By: dmmiller fb-gh-sync-id: 61346d99414d331d3420f44a4c5f6341b0973be6 fbshipit-source-id: 61346d99414d331d3420f44a4c5f6341b0973be6
108 lines
3.1 KiB
JavaScript
108 lines
3.1 KiB
JavaScript
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*
|
|
* @providesModule Modal
|
|
* @flow
|
|
*/
|
|
'use strict';
|
|
|
|
const Platform = require('Platform');
|
|
const PropTypes = require('ReactPropTypes');
|
|
const React = require('React');
|
|
const StyleSheet = require('StyleSheet');
|
|
const UIManager = require('UIManager');
|
|
const View = require('View');
|
|
const deprecatedPropType = require('deprecatedPropType');
|
|
|
|
const requireNativeComponent = require('requireNativeComponent');
|
|
const RCTModalHostView = requireNativeComponent('RCTModalHostView', null);
|
|
|
|
/**
|
|
* A Modal component covers the native view (e.g. UIViewController, Activity)
|
|
* that contains the React Native root.
|
|
*
|
|
* Use Modal in hybrid apps that embed React Native; Modal allows the portion of
|
|
* your app written in React Native to present content above the enclosing
|
|
* native view hierarchy.
|
|
*
|
|
* In apps written with React Native from the root view down, you should use
|
|
* Navigator instead of Modal. With a top-level Navigator, you have more control
|
|
* over how to present the modal scene over the rest of your app by using the
|
|
* configureScene property.
|
|
*/
|
|
class Modal extends React.Component {
|
|
static propTypes = {
|
|
animated: deprecatedPropType(
|
|
PropTypes.bool,
|
|
'Use the `animationType` prop instead.'
|
|
),
|
|
animationType: PropTypes.oneOf(['none', 'slide', 'fade']),
|
|
transparent: PropTypes.bool,
|
|
visible: PropTypes.bool,
|
|
onRequestClose: Platform.OS === 'android' ? PropTypes.func.isRequired : PropTypes.func,
|
|
onShow: PropTypes.func,
|
|
};
|
|
|
|
static defaultProps = {
|
|
visible: true,
|
|
};
|
|
|
|
render(): ?ReactElement {
|
|
if (this.props.visible === false) {
|
|
return null;
|
|
}
|
|
|
|
const containerStyles = {
|
|
backgroundColor: this.props.transparent ? 'transparent' : 'white',
|
|
top: Platform.OS === 'android' && Platform.Version >= 19 ? UIManager.RCTModalHostView.Constants.StatusBarHeight : 0,
|
|
};
|
|
|
|
let animationType = this.props.animationType;
|
|
if (!animationType) {
|
|
// manually setting default prop here to keep support for the deprecated 'animated' prop
|
|
animationType = 'none';
|
|
if (this.props.animated) {
|
|
animationType = 'slide';
|
|
}
|
|
}
|
|
|
|
return (
|
|
<RCTModalHostView
|
|
animationType={animationType}
|
|
transparent={this.props.transparent}
|
|
onRequestClose={this.props.onRequestClose}
|
|
onShow={this.props.onShow}
|
|
style={styles.modal}
|
|
onStartShouldSetResponder={this._shouldSetResponder}
|
|
>
|
|
<View style={[styles.container, containerStyles]}>
|
|
{this.props.children}
|
|
</View>
|
|
</RCTModalHostView>
|
|
);
|
|
}
|
|
|
|
// We don't want any responder events bubbling out of the modal.
|
|
_shouldSetResponder(): boolean {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
modal: {
|
|
position: 'absolute',
|
|
},
|
|
container: {
|
|
position: 'absolute',
|
|
left: 0,
|
|
top: 0,
|
|
}
|
|
});
|
|
|
|
module.exports = Modal;
|