mirror of
https://github.com/status-im/react-native.git
synced 2025-01-14 19:44:13 +00:00
09958618c5
Summary:Current docs show an Appetize.io example for AlertIOS doc. This pull request adds that feature across all applicable iOS and Android docs. So if a doc has an example in UIExplorer, it shows up in the top right and clicking to Play should navigate to the relevant example. The changes here also touched NavigationExperimental to fix a typo that prevented iOS deep link from working. Code was also added to help support Android deep links but there's an outstanding issue (a race condition) around how Android deep links trigger getInitialURL in NavigationRootContainer that prevents this from fully working. For adding the docs, a few things were done outside this pull request: 1/ Release builds for UIExplorer Android and iOS apps were uploaded to Appetize.io. The Appetize.io info (public key to run the build) is embedded in the docs. 2/ The iOS build was generated by making a few changes to get a local bundle. The current UIExplorer set up doesn't support "react-native run-ios". Regarding the Appetize bu Closes https://github.com/facebook/react-native/pull/6306 Differential Revision: D3129651 Pulled By: bestander fb-gh-sync-id: d296d64db8236faa36f35484bb6b362990caf934 fbshipit-source-id: d296d64db8236faa36f35484bb6b362990caf934
228 lines
6.8 KiB
JavaScript
228 lines
6.8 KiB
JavaScript
/**
|
|
* The examples provided by Facebook are for non-commercial testing and
|
|
* evaluation purposes only.
|
|
*
|
|
* Facebook reserves all rights not expressly granted.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
|
|
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
* @providesModule UIExplorerApp
|
|
* @flow
|
|
*/
|
|
'use strict';
|
|
|
|
const React = require('react-native');
|
|
const {
|
|
AppRegistry,
|
|
BackAndroid,
|
|
Dimensions,
|
|
DrawerLayoutAndroid,
|
|
NavigationExperimental,
|
|
StyleSheet,
|
|
ToolbarAndroid,
|
|
View,
|
|
StatusBar,
|
|
} = React;
|
|
const {
|
|
RootContainer: NavigationRootContainer,
|
|
} = NavigationExperimental;
|
|
const UIExplorerExampleList = require('./UIExplorerExampleList');
|
|
const UIExplorerList = require('./UIExplorerList');
|
|
const UIExplorerNavigationReducer = require('./UIExplorerNavigationReducer');
|
|
const UIExplorerStateTitleMap = require('./UIExplorerStateTitleMap');
|
|
const URIActionMap = require('./URIActionMap');
|
|
|
|
var DRAWER_WIDTH_LEFT = 56;
|
|
|
|
type Props = {
|
|
exampleFromAppetizeParams: string,
|
|
};
|
|
|
|
type State = {
|
|
initialExampleUri: ?string,
|
|
};
|
|
|
|
class UIExplorerApp extends React.Component {
|
|
_handleOpenInitialExample: Function;
|
|
state: State;
|
|
constructor(props: Props) {
|
|
super(props);
|
|
this._handleOpenInitialExample = this._handleOpenInitialExample.bind(this);
|
|
this.state = {
|
|
initialExampleUri: props.exampleFromAppetizeParams,
|
|
};
|
|
}
|
|
|
|
componentWillMount() {
|
|
BackAndroid.addEventListener('hardwareBackPress', this._handleBackButtonPress.bind(this));
|
|
}
|
|
|
|
componentDidMount() {
|
|
// There's a race condition if we try to navigate to the specified example
|
|
// from the initial props at the same time the navigation logic is setting
|
|
// up the initial navigation state. This hack adds a delay to avoid this
|
|
// scenario. So after the initial example list is shown, we then transition
|
|
// to the initial example.
|
|
setTimeout(this._handleOpenInitialExample, 500);
|
|
}
|
|
|
|
render() {
|
|
return (
|
|
<NavigationRootContainer
|
|
persistenceKey="UIExplorerStateNavState"
|
|
ref={navRootRef => { this._navigationRootRef = navRootRef; }}
|
|
reducer={UIExplorerNavigationReducer}
|
|
renderNavigation={this._renderApp.bind(this)}
|
|
linkingActionMap={URIActionMap}
|
|
/>
|
|
);
|
|
}
|
|
|
|
_handleOpenInitialExample() {
|
|
if (this.state.initialExampleUri) {
|
|
const exampleAction = URIActionMap(this.state.initialExampleUri);
|
|
if (exampleAction && this._navigationRootRef) {
|
|
this._navigationRootRef.handleNavigation(exampleAction);
|
|
}
|
|
}
|
|
this.setState({initialExampleUri: null});
|
|
}
|
|
|
|
_renderApp(navigationState, onNavigate) {
|
|
if (!navigationState) {
|
|
return null;
|
|
}
|
|
return (
|
|
<DrawerLayoutAndroid
|
|
drawerPosition={DrawerLayoutAndroid.positions.Left}
|
|
drawerWidth={Dimensions.get('window').width - DRAWER_WIDTH_LEFT}
|
|
keyboardDismissMode="on-drag"
|
|
onDrawerOpen={() => {
|
|
this._overrideBackPressForDrawerLayout = true;
|
|
}}
|
|
onDrawerClose={() => {
|
|
this._overrideBackPressForDrawerLayout = false;
|
|
}}
|
|
ref={(drawer) => { this.drawer = drawer; }}
|
|
renderNavigationView={this._renderDrawerContent.bind(this, onNavigate)}
|
|
statusBarBackgroundColor="#589c90">
|
|
{this._renderNavigation(navigationState, onNavigate)}
|
|
</DrawerLayoutAndroid>
|
|
);
|
|
}
|
|
|
|
_renderDrawerContent(onNavigate) {
|
|
return (
|
|
<View style={styles.drawerContentWrapper}>
|
|
<UIExplorerExampleList
|
|
list={UIExplorerList}
|
|
displayTitleRow={true}
|
|
disableSearch={true}
|
|
onNavigate={(action) => {
|
|
this.drawer && this.drawer.closeDrawer();
|
|
onNavigate(action);
|
|
}}
|
|
/>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
_renderNavigation(navigationState, onNavigate) {
|
|
if (navigationState.externalExample) {
|
|
var Component = UIExplorerList.Modules[navigationState.externalExample];
|
|
return (
|
|
<Component
|
|
onExampleExit={() => {
|
|
onNavigate(NavigationRootContainer.getBackAction());
|
|
}}
|
|
ref={(example) => { this._exampleRef = example; }}
|
|
/>
|
|
);
|
|
}
|
|
const {stack} = navigationState;
|
|
const title = UIExplorerStateTitleMap(stack.children[stack.index]);
|
|
const index = stack.children.length <= 1 ? 1 : stack.index;
|
|
|
|
if (stack && stack.children[index]) {
|
|
const {key} = stack.children[index];
|
|
const ExampleModule = UIExplorerList.Modules[key];
|
|
const ExampleComponent = UIExplorerExampleList.makeRenderable(ExampleModule);
|
|
return (
|
|
<View style={styles.container}>
|
|
<ToolbarAndroid
|
|
logo={require('image!launcher_icon')}
|
|
navIcon={require('image!ic_menu_black_24dp')}
|
|
onIconClicked={() => this.drawer.openDrawer()}
|
|
style={styles.toolbar}
|
|
title={title}
|
|
/>
|
|
<ExampleComponent
|
|
ref={(example) => { this._exampleRef = example; }}
|
|
/>
|
|
</View>
|
|
);
|
|
}
|
|
return (
|
|
<View style={styles.container}>
|
|
<ToolbarAndroid
|
|
logo={require('image!launcher_icon')}
|
|
navIcon={require('image!ic_menu_black_24dp')}
|
|
onIconClicked={() => this.drawer.openDrawer()}
|
|
style={styles.toolbar}
|
|
title={title}
|
|
/>
|
|
<UIExplorerExampleList
|
|
list={UIExplorerList}
|
|
{...stack.children[0]}
|
|
/>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
_handleBackButtonPress() {
|
|
if (this._overrideBackPressForDrawerLayout) {
|
|
// This hack is necessary because drawer layout provides an imperative API
|
|
// with open and close methods. This code would be cleaner if the drawer
|
|
// layout provided an `isOpen` prop and allowed us to pass a `onDrawerClose` handler.
|
|
this.drawer && this.drawer.closeDrawer();
|
|
return true;
|
|
}
|
|
if (
|
|
this._exampleRef &&
|
|
this._exampleRef.handleBackAction &&
|
|
this._exampleRef.handleBackAction()
|
|
) {
|
|
return true;
|
|
}
|
|
if (this._navigationRootRef) {
|
|
return this._navigationRootRef.handleNavigation(
|
|
NavigationRootContainer.getBackAction()
|
|
);
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
flex: 1,
|
|
},
|
|
toolbar: {
|
|
backgroundColor: '#E9EAED',
|
|
height: 56,
|
|
},
|
|
drawerContentWrapper: {
|
|
paddingTop: StatusBar.currentHeight,
|
|
backgroundColor: 'white',
|
|
},
|
|
});
|
|
|
|
AppRegistry.registerComponent('UIExplorerApp', () => UIExplorerApp);
|
|
|
|
module.exports = UIExplorerApp;
|