Files
react-native/packages/rn-tester/js/examples/Layout/LayoutExample.js
T
Ankit Tiwari 1270873ed6 RNTester UI Redesign (#29685)
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>
2020-08-26 08:45:57 -07:00

208 lines
6.2 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 strict-local
*/
'use strict';
const RNTesterBlock = require('../../components/RNTesterBlock');
const RNTesterPage = require('../../components/RNTesterPage');
const React = require('react');
const {StyleSheet, Text, View} = require('react-native');
class Circle extends React.Component<$FlowFixMeProps> {
render() {
const size = this.props.size || 20;
const backgroundColor = this.props.bgColor || '#527fe4';
return (
<View
style={{
borderRadius: size / 2,
backgroundColor: backgroundColor,
width: size,
height: size,
margin: 1,
}}
/>
);
}
}
class CircleBlock extends React.Component<$FlowFixMeProps> {
render() {
const circleStyle = {
flexDirection: 'row',
backgroundColor: '#f6f7f8',
borderWidth: 0.5,
borderColor: '#d6d7da',
marginBottom: 2,
};
return (
<View style={[circleStyle, this.props.style]}>{this.props.children}</View>
);
}
}
class LayoutExample extends React.Component<$FlowFixMeProps> {
render(): React.Node {
const fiveColoredCircles = [
<Circle bgColor="#527fe4" key="blue" />,
<Circle bgColor="#D443E3" key="violet" />,
<Circle bgColor="#FF9049" key="orange" />,
<Circle bgColor="#FFE649" key="yellow" />,
<Circle bgColor="#7FE040" key="green" />,
];
return (
<RNTesterPage title={this.props.navigator ? null : 'Layout'}>
<RNTesterBlock title="Flex Direction">
<Text>row</Text>
<CircleBlock style={{flexDirection: 'row'}}>
{fiveColoredCircles}
</CircleBlock>
<Text>row-reverse</Text>
<CircleBlock style={{flexDirection: 'row-reverse'}}>
{fiveColoredCircles}
</CircleBlock>
<Text>column</Text>
<CircleBlock style={{flexDirection: 'column'}}>
{fiveColoredCircles}
</CircleBlock>
<Text>column-reverse</Text>
<CircleBlock style={{flexDirection: 'column-reverse'}}>
{fiveColoredCircles}
</CircleBlock>
<View
style={[
styles.overlay,
{position: 'absolute', top: 15, left: 160},
]}>
<Text>{'top: 15, left: 160'}</Text>
</View>
</RNTesterBlock>
<RNTesterBlock title="Justify Content - Main Direction">
<Text>flex-start</Text>
<CircleBlock style={{justifyContent: 'flex-start'}}>
{fiveColoredCircles}
</CircleBlock>
<Text>center</Text>
<CircleBlock style={{justifyContent: 'center'}}>
{fiveColoredCircles}
</CircleBlock>
<Text>flex-end</Text>
<CircleBlock style={{justifyContent: 'flex-end'}}>
{fiveColoredCircles}
</CircleBlock>
<Text>space-between</Text>
<CircleBlock style={{justifyContent: 'space-between'}}>
{fiveColoredCircles}
</CircleBlock>
<Text>space-around</Text>
<CircleBlock style={{justifyContent: 'space-around'}}>
{fiveColoredCircles}
</CircleBlock>
</RNTesterBlock>
<RNTesterBlock title="Align Items - Other Direction">
<Text>flex-start</Text>
<CircleBlock style={{alignItems: 'flex-start', height: 30}}>
<Circle size={15} />
<Circle size={10} />
<Circle size={20} />
<Circle size={17} />
<Circle size={12} />
<Circle size={15} />
<Circle size={10} />
<Circle size={20} />
<Circle size={17} />
<Circle size={12} />
<Circle size={15} />
<Circle size={10} />
<Circle size={20} />
<Circle size={17} />
<Circle size={12} />
<Circle size={15} />
<Circle size={8} />
</CircleBlock>
<Text>center</Text>
<CircleBlock style={{alignItems: 'center', height: 30}}>
<Circle size={15} />
<Circle size={10} />
<Circle size={20} />
<Circle size={17} />
<Circle size={12} />
<Circle size={15} />
<Circle size={10} />
<Circle size={20} />
<Circle size={17} />
<Circle size={12} />
<Circle size={15} />
<Circle size={10} />
<Circle size={20} />
<Circle size={17} />
<Circle size={12} />
<Circle size={15} />
<Circle size={8} />
</CircleBlock>
<Text>flex-end</Text>
<CircleBlock style={{alignItems: 'flex-end', height: 30}}>
<Circle size={15} />
<Circle size={10} />
<Circle size={20} />
<Circle size={17} />
<Circle size={12} />
<Circle size={15} />
<Circle size={10} />
<Circle size={20} />
<Circle size={17} />
<Circle size={12} />
<Circle size={15} />
<Circle size={10} />
<Circle size={20} />
<Circle size={17} />
<Circle size={12} />
<Circle size={15} />
<Circle size={8} />
</CircleBlock>
</RNTesterBlock>
<RNTesterBlock title="Flex Wrap">
<CircleBlock style={{flexWrap: 'wrap'}}>
{'oooooooooooooooo'.split('').map((char, i) => (
<Circle key={i} />
))}
</CircleBlock>
</RNTesterBlock>
</RNTesterPage>
);
}
}
const styles = StyleSheet.create({
overlay: {
backgroundColor: '#aaccff',
borderRadius: 10,
borderWidth: 0.5,
opacity: 0.5,
padding: 5,
},
});
exports.title = 'Layout - Flexbox';
exports.category = 'UI';
exports.description = 'Examples of using the flexbox API to layout views.';
exports.displayName = 'LayoutExample';
exports.examples = [
{
title: 'Simple layout using flexbox',
render: function(): React.Element<typeof LayoutExample> {
return <LayoutExample />;
},
},
];