react-native/Libraries/ReactIOS/renderApplication.android.js
Sebastian Markbage 613ca14612 React.findNodeHandle -> ReactNative.findNodeHandle
Summary:Since the React 0.14 split of modules, the findNodeHandle feature is part of the
renderer and not the generic React API.

This just greps for React.findNodeHandle and replace them with ReactNative.findNodeHandle. I fixed up the imports manually.

I also found two callers each of ReactNative.createClass and React.render with the exception of downstream and examples will fix them separately.

I'll need to find more things like `var { PropTypes } = ReactNative;` separately. I think this is a good start though.

Reviewed By: vjeux

Differential Revision: D3149356

fb-gh-sync-id: 50ed60bc67270b16f561d4c641f2f19e85724d3b
fbshipit-source-id: 50ed60bc67270b16f561d4c641f2f19e85724d3b
2016-04-07 19:44:31 -07:00

141 lines
3.4 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 renderApplication
*/
'use strict';
var Inspector = require('Inspector');
var Portal = require('Portal');
var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
var React = require('React');
var ReactNative = require('ReactNative');
var StyleSheet = require('StyleSheet');
var Subscribable = require('Subscribable');
var View = require('View');
var invariant = require('fbjs/lib/invariant');
var YellowBox = __DEV__ ? require('YellowBox') : null;
// require BackAndroid so it sets the default handler that exits the app if no listeners respond
require('BackAndroid');
var AppContainer = React.createClass({
mixins: [Subscribable.Mixin],
getInitialState: function() {
return {
enabled: __DEV__,
inspectorVisible: false,
rootNodeHandle: null,
rootImportanceForAccessibility: 'auto',
};
},
toggleElementInspector: function() {
this.setState({
inspectorVisible: !this.state.inspectorVisible,
rootNodeHandle: ReactNative.findNodeHandle(this.refs.main),
});
},
componentDidMount: function() {
this.addListenerOn(
RCTDeviceEventEmitter,
'toggleElementInspector',
this.toggleElementInspector
);
this._unmounted = false;
},
renderInspector: function() {
return this.state.inspectorVisible ?
<Inspector
rootTag={this.props.rootTag}
inspectedViewTag={this.state.rootNodeHandle}
/> :
null;
},
componentWillUnmount: function() {
this._unmounted = true;
},
setRootAccessibility: function(modalVisible) {
if (this._unmounted) {
return;
}
this.setState({
rootImportanceForAccessibility: modalVisible ? 'no-hide-descendants' : 'auto',
});
},
render: function() {
var RootComponent = this.props.rootComponent;
var appView =
<View
ref="main"
collapsable={!this.state.inspectorVisible}
style={styles.appContainer}>
<RootComponent
{...this.props.initialProps}
rootTag={this.props.rootTag}
importantForAccessibility={this.state.rootImportanceForAccessibility}/>
<Portal
onModalVisibilityChanged={this.setRootAccessibility}/>
</View>;
let yellowBox = null;
if (__DEV__) {
yellowBox = <YellowBox />;
}
return this.state.enabled ?
<View style={styles.appContainer}>
{appView}
{yellowBox}
{this.renderInspector()}
</View> :
appView;
}
});
function renderApplication<D, P, S>(
RootComponent: ReactClass<P>,
initialProps: P,
rootTag: any
) {
invariant(
rootTag,
'Expect to have a valid rootTag, instead got ', rootTag
);
ReactNative.render(
<AppContainer
rootComponent={RootComponent}
initialProps={initialProps}
rootTag={rootTag} />,
rootTag
);
}
var styles = StyleSheet.create({
// This is needed so the application covers the whole screen
// and therefore the contents of the Portal are not clipped.
appContainer: {
position: 'absolute',
left: 0,
top: 0,
right: 0,
bottom: 0,
},
});
module.exports = renderApplication;