mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: This Pull request adds the UI changes to the RNTester app as discussed in the MLH Fellowship. This list is not exhaustive. - The initial App screen is redesigned. - A bottom Navbar has been added. - Filter pills are added. - The list card UI is updated. - The example page UI is updated. - Recently Viewed Sections are added. It shows the last 5 recently viewed components/APIs. - Bookmarking functionality is added. - The documentation URL is added to the example page. - RNTester doesn't lose its state on a hard refresh (even on iOS). <img width="373" src="https://user-images.githubusercontent.com/22813027/90530113-20346180-e192-11ea-8ef6-789fa25b402b.png" /> <img width="373" src="https://user-images.githubusercontent.com/22813027/90530112-20346180-e192-11ea-9539-706b540fcc5f.png" /> <img width="373" src="https://user-images.githubusercontent.com/22813027/90530100-1d397100-e192-11ea-8836-b88070643233.png" /> <img width="373" src="https://user-images.githubusercontent.com/22813027/90530110-1f9bcb00-e192-11ea-936b-64ee75fa4289.png" /> Pull Request resolved: https://github.com/facebook/react-native/pull/29685 Test Plan: Imported from GitHub, without a `Test Plan:` line. {F302717939} Note: this failed **before** this diff too: {F302745716} Reviewed By: mdvacca, cpojer Differential Revision: D23240434 fbshipit-source-id: 65e2766a6a097eca0e0d0fda8dadf6871e9276c2 Co-authored-by: agarwalmanya <manya18ag@gmail.com> Co-authored-by: chirag-singhal <csinghal208@gmail.com> Co-authored-by: Ansh Godha <ag759@cornell.edu> Co-authored-by: Yash Kumar Verma <yk.verma2000@gmail.com> Co-authored-by: Sanskar Jethi <sansyrox@gmail.com> Co-authored-by: Aniketh Saha <anik220798@gmail.com> Co-authored-by: Xtremilicious <nilarjundas@outlook.com> Co-authored-by: Jani Evakallio <jani.evakallio@gmail.com>
242 lines
6.6 KiB
JavaScript
242 lines
6.6 KiB
JavaScript
/**
|
|
* 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
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const React = require('react');
|
|
|
|
const {StyleSheet, Text, View} = require('react-native');
|
|
|
|
class ExampleBox extends React.Component<$FlowFixMeProps, $FlowFixMeState> {
|
|
state = {
|
|
log: [],
|
|
};
|
|
|
|
handleLog = msg => {
|
|
this.state.log = this.state.log.concat([msg]);
|
|
};
|
|
|
|
flushReactChanges = () => {
|
|
this.forceUpdate();
|
|
};
|
|
|
|
/**
|
|
* Capture phase of bubbling to append separator before any of the bubbling
|
|
* happens.
|
|
*/
|
|
handleTouchCapture = () => {
|
|
this.state.log = this.state.log.concat(['---']);
|
|
};
|
|
|
|
render() {
|
|
return (
|
|
<View>
|
|
<View
|
|
onTouchEndCapture={this.handleTouchCapture}
|
|
onTouchStart={this.flushReactChanges}>
|
|
{/* $FlowFixMe(>=0.53.0 site=react_native_fb,react_native_oss) This
|
|
* comment suppresses an error when upgrading Flow's support for
|
|
* React. To see the error delete this comment and run Flow. */}
|
|
<this.props.Component onLog={this.handleLog} />
|
|
</View>
|
|
<View style={styles.logBox}>
|
|
<DemoText style={styles.logText}>
|
|
{this.state.log.join('\n')}
|
|
</DemoText>
|
|
</View>
|
|
</View>
|
|
);
|
|
}
|
|
}
|
|
|
|
class NoneExample extends React.Component<$FlowFixMeProps> {
|
|
render() {
|
|
return (
|
|
<View
|
|
onTouchStart={() => this.props.onLog('A unspecified touched')}
|
|
style={styles.box}>
|
|
<DemoText style={styles.text}>A: unspecified</DemoText>
|
|
<View
|
|
pointerEvents="none"
|
|
onTouchStart={() => this.props.onLog('B none touched')}
|
|
style={[styles.box, styles.boxPassedThrough]}>
|
|
<DemoText style={[styles.text, styles.textPassedThrough]}>
|
|
B: none
|
|
</DemoText>
|
|
<View
|
|
onTouchStart={() => this.props.onLog('C unspecified touched')}
|
|
style={[styles.box, styles.boxPassedThrough]}>
|
|
<DemoText style={[styles.text, styles.textPassedThrough]}>
|
|
C: unspecified
|
|
</DemoText>
|
|
</View>
|
|
</View>
|
|
</View>
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Special demo text that makes itself untouchable so that it doesn't destroy
|
|
* the experiment and confuse the output.
|
|
*/
|
|
class DemoText extends React.Component<$FlowFixMeProps> {
|
|
render() {
|
|
return (
|
|
<View pointerEvents="none">
|
|
<Text style={this.props.style}>{this.props.children}</Text>
|
|
</View>
|
|
);
|
|
}
|
|
}
|
|
|
|
class BoxNoneExample extends React.Component<$FlowFixMeProps> {
|
|
render() {
|
|
return (
|
|
<View
|
|
onTouchStart={() => this.props.onLog('A unspecified touched')}
|
|
style={styles.box}>
|
|
<DemoText style={styles.text}>A: unspecified</DemoText>
|
|
<View
|
|
pointerEvents="box-none"
|
|
onTouchStart={() => this.props.onLog('B box-none touched')}
|
|
style={[styles.box, styles.boxPassedThrough]}>
|
|
<DemoText style={[styles.text, styles.textPassedThrough]}>
|
|
B: box-none
|
|
</DemoText>
|
|
<View
|
|
onTouchStart={() => this.props.onLog('C unspecified touched')}
|
|
style={styles.box}>
|
|
<DemoText style={styles.text}>C: unspecified</DemoText>
|
|
</View>
|
|
<View
|
|
pointerEvents="auto"
|
|
onTouchStart={() =>
|
|
this.props.onLog('C explicitly unspecified touched')
|
|
}
|
|
style={[styles.box]}>
|
|
<DemoText style={[styles.text]}>C: explicitly unspecified</DemoText>
|
|
</View>
|
|
</View>
|
|
</View>
|
|
);
|
|
}
|
|
}
|
|
|
|
class BoxOnlyExample extends React.Component<$FlowFixMeProps> {
|
|
render() {
|
|
return (
|
|
<View
|
|
onTouchStart={() => this.props.onLog('A unspecified touched')}
|
|
style={styles.box}>
|
|
<DemoText style={styles.text}>A: unspecified</DemoText>
|
|
<View
|
|
pointerEvents="box-only"
|
|
onTouchStart={() => this.props.onLog('B box-only touched')}
|
|
style={styles.box}>
|
|
<DemoText style={styles.text}>B: box-only</DemoText>
|
|
<View
|
|
onTouchStart={() => this.props.onLog('C unspecified touched')}
|
|
style={[styles.box, styles.boxPassedThrough]}>
|
|
<DemoText style={[styles.text, styles.textPassedThrough]}>
|
|
C: unspecified
|
|
</DemoText>
|
|
</View>
|
|
<View
|
|
pointerEvents="auto"
|
|
onTouchStart={() =>
|
|
this.props.onLog('C explicitly unspecified touched')
|
|
}
|
|
style={[styles.box, styles.boxPassedThrough]}>
|
|
<DemoText style={[styles.text, styles.textPassedThrough]}>
|
|
C: explicitly unspecified
|
|
</DemoText>
|
|
</View>
|
|
</View>
|
|
</View>
|
|
);
|
|
}
|
|
}
|
|
|
|
type ExampleClass = {
|
|
Component: React.ComponentType<any>,
|
|
title: string,
|
|
description: string,
|
|
...
|
|
};
|
|
|
|
const exampleClasses: Array<ExampleClass> = [
|
|
{
|
|
Component: NoneExample,
|
|
title: '`none`',
|
|
description:
|
|
'`none` causes touch events on the container and its child components to pass through to the parent container.',
|
|
},
|
|
{
|
|
Component: BoxNoneExample,
|
|
title: '`box-none`',
|
|
description:
|
|
'`box-none` causes touch events on the container to pass through and will only detect touch events on its child components.',
|
|
},
|
|
{
|
|
Component: BoxOnlyExample,
|
|
title: '`box-only`',
|
|
description:
|
|
"`box-only` causes touch events on the container's child components to pass through and will only detect touch events on the container itself.",
|
|
},
|
|
];
|
|
|
|
const infoToExample = info => {
|
|
return {
|
|
title: info.title,
|
|
description: info.description,
|
|
render: function() {
|
|
return <ExampleBox key={info.title} Component={info.Component} />;
|
|
},
|
|
};
|
|
};
|
|
|
|
const styles = StyleSheet.create({
|
|
text: {
|
|
fontSize: 10,
|
|
color: '#5577cc',
|
|
},
|
|
textPassedThrough: {
|
|
color: '#88aadd',
|
|
},
|
|
box: {
|
|
backgroundColor: '#aaccff',
|
|
borderWidth: 1,
|
|
borderColor: '#7799cc',
|
|
padding: 10,
|
|
margin: 5,
|
|
},
|
|
boxPassedThrough: {
|
|
borderColor: '#99bbee',
|
|
},
|
|
logText: {
|
|
fontSize: 9,
|
|
},
|
|
logBox: {
|
|
padding: 20,
|
|
margin: 10,
|
|
borderWidth: 0.5,
|
|
borderColor: '#f0f0f0',
|
|
backgroundColor: '#f9f9f9',
|
|
},
|
|
});
|
|
|
|
exports.framework = 'React';
|
|
exports.title = 'Pointer Events';
|
|
exports.category = 'Basic';
|
|
exports.description = ('Demonstrates the use of the pointerEvents prop of a ' +
|
|
'View to control how touches should be handled.': string);
|
|
exports.examples = (exampleClasses.map(infoToExample): Array<any>);
|