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>
339 lines
7.6 KiB
JavaScript
339 lines
7.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';
|
|
|
|
import React, {useEffect, useState} from 'react';
|
|
import {Animated, StyleSheet, Text, View} from 'react-native';
|
|
|
|
import type {Node, Element} from 'react';
|
|
|
|
function AnimateTansformSingleProp() {
|
|
const [theta] = useState(new Animated.Value(45));
|
|
const animate = () => {
|
|
theta.setValue(0);
|
|
Animated.timing(theta, {
|
|
toValue: 100,
|
|
duration: 3000,
|
|
useNativeDriver: false,
|
|
}).start(animate);
|
|
};
|
|
|
|
useEffect(() => {
|
|
animate();
|
|
});
|
|
|
|
return (
|
|
<View style={styles.flipCardContainer}>
|
|
<Animated.View
|
|
style={[
|
|
styles.box6,
|
|
{
|
|
transform: [
|
|
{
|
|
rotate: theta.interpolate({
|
|
inputRange: [0, 100],
|
|
/* $FlowFixMe(>=0.38.0) - Flow error detected during the
|
|
* deployment of v0.38.0. To see the error, remove this
|
|
* comment and run flow */
|
|
outputRange: ['0deg', '360deg'],
|
|
}),
|
|
},
|
|
],
|
|
},
|
|
]}>
|
|
<Text style={styles.flipText}>This text is flipping great.</Text>
|
|
</Animated.View>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
function Flip() {
|
|
const [theta] = useState(new Animated.Value(45));
|
|
const animate = () => {
|
|
theta.setValue(0);
|
|
Animated.timing(theta, {
|
|
toValue: 360,
|
|
duration: 5000,
|
|
useNativeDriver: false,
|
|
}).start(animate);
|
|
};
|
|
|
|
useEffect(() => {
|
|
animate();
|
|
});
|
|
|
|
return (
|
|
<View style={styles.flipCardContainer}>
|
|
<Animated.View
|
|
style={[
|
|
styles.flipCard,
|
|
{
|
|
transform: [
|
|
{perspective: 850},
|
|
{
|
|
rotateX: theta.interpolate({
|
|
inputRange: [0, 180],
|
|
/* $FlowFixMe(>=0.38.0) - Flow error detected during the
|
|
* deployment of v0.38.0. To see the error, remove this
|
|
* comment and run flow */
|
|
outputRange: ['0deg', '180deg'],
|
|
}),
|
|
},
|
|
],
|
|
},
|
|
]}>
|
|
<Text style={styles.flipText}>This text is flipping great.</Text>
|
|
</Animated.View>
|
|
<Animated.View
|
|
style={[
|
|
styles.flipCard,
|
|
styles.flipCard1,
|
|
{
|
|
transform: [
|
|
{perspective: 850},
|
|
{
|
|
rotateX: theta.interpolate({
|
|
inputRange: [0, 180],
|
|
/* $FlowFixMe(>=0.38.0) - Flow error detected during the
|
|
* deployment of v0.38.0. To see the error, remove this
|
|
* comment and run flow */
|
|
outputRange: ['180deg', '360deg'],
|
|
}),
|
|
},
|
|
],
|
|
},
|
|
]}>
|
|
<Text style={styles.flipText}>On the flip side...</Text>
|
|
</Animated.View>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
height: 500,
|
|
},
|
|
box1: {
|
|
left: 0,
|
|
backgroundColor: 'green',
|
|
height: 50,
|
|
position: 'absolute',
|
|
top: 0,
|
|
transform: [
|
|
{translateX: 100},
|
|
{translateY: 50},
|
|
{rotate: '30deg'},
|
|
{scaleX: 2},
|
|
{scaleY: 2},
|
|
],
|
|
width: 50,
|
|
},
|
|
box2: {
|
|
left: 0,
|
|
backgroundColor: 'purple',
|
|
height: 50,
|
|
position: 'absolute',
|
|
top: 0,
|
|
transform: [
|
|
{scaleX: 2},
|
|
{scaleY: 2},
|
|
{translateX: 100},
|
|
{translateY: 50},
|
|
{rotate: '30deg'},
|
|
],
|
|
width: 50,
|
|
},
|
|
box3step1: {
|
|
left: 0,
|
|
backgroundColor: 'lightpink',
|
|
height: 50,
|
|
position: 'absolute',
|
|
top: 0,
|
|
transform: [{rotate: '30deg'}],
|
|
width: 50,
|
|
},
|
|
box3step2: {
|
|
left: 0,
|
|
backgroundColor: 'hotpink',
|
|
height: 50,
|
|
opacity: 0.5,
|
|
position: 'absolute',
|
|
top: 0,
|
|
transform: [{rotate: '30deg'}, {scaleX: 2}, {scaleY: 2}],
|
|
width: 50,
|
|
},
|
|
box3step3: {
|
|
left: 0,
|
|
backgroundColor: 'deeppink',
|
|
height: 50,
|
|
opacity: 0.5,
|
|
position: 'absolute',
|
|
top: 0,
|
|
transform: [
|
|
{rotate: '30deg'},
|
|
{scaleX: 2},
|
|
{scaleY: 2},
|
|
{translateX: 100},
|
|
{translateY: 50},
|
|
],
|
|
width: 50,
|
|
},
|
|
box4: {
|
|
left: 0,
|
|
backgroundColor: 'darkorange',
|
|
height: 50,
|
|
position: 'absolute',
|
|
top: 0,
|
|
transform: [{translate: [200, 350]}, {scale: 2.5}, {rotate: '-0.2rad'}],
|
|
width: 100,
|
|
},
|
|
box5: {
|
|
backgroundColor: 'maroon',
|
|
height: 50,
|
|
position: 'absolute',
|
|
right: 0,
|
|
top: 0,
|
|
width: 50,
|
|
},
|
|
box5Transform: {
|
|
transform: [{translate: [-50, 35]}, {rotate: '50deg'}, {scale: 2}],
|
|
},
|
|
box6: {
|
|
backgroundColor: 'salmon',
|
|
alignSelf: 'center',
|
|
},
|
|
flipCardContainer: {
|
|
marginVertical: 40,
|
|
flex: 1,
|
|
alignSelf: 'center',
|
|
},
|
|
flipCard: {
|
|
width: 200,
|
|
height: 200,
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
backgroundColor: 'blue',
|
|
backfaceVisibility: 'hidden',
|
|
},
|
|
flipCard1: {
|
|
position: 'absolute',
|
|
top: 0,
|
|
backgroundColor: 'red',
|
|
},
|
|
flipText: {
|
|
width: 90,
|
|
fontSize: 20,
|
|
color: 'white',
|
|
fontWeight: 'bold',
|
|
},
|
|
});
|
|
|
|
exports.title = 'Transforms';
|
|
exports.category = 'UI';
|
|
exports.documentationURL = 'https://reactnative.dev/docs/transforms';
|
|
exports.description = 'View transforms';
|
|
exports.examples = [
|
|
{
|
|
title: 'Perspective, Rotate, Animation',
|
|
description: 'perspective: 850, rotateX: Animated.timing(0 -> 360)',
|
|
render(): Element<any> {
|
|
return <Flip />;
|
|
},
|
|
},
|
|
{
|
|
title: 'Translate, Rotate, Scale',
|
|
description:
|
|
"translateX: 100, translateY: 50, rotate: '30deg', scaleX: 2, scaleY: 2",
|
|
render(): Node {
|
|
return (
|
|
<View style={styles.container}>
|
|
<View style={styles.box1} />
|
|
</View>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
title: 'Scale, Translate, Rotate, ',
|
|
description:
|
|
"scaleX: 2, scaleY: 2, translateX: 100, translateY: 50, rotate: '30deg'",
|
|
render(): Node {
|
|
return (
|
|
<View style={styles.container}>
|
|
<View style={styles.box2} />
|
|
</View>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
title: 'Rotate',
|
|
description: "rotate: '30deg'",
|
|
render(): Node {
|
|
return (
|
|
<View style={styles.container}>
|
|
<View style={styles.box3step1} />
|
|
</View>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
title: 'Rotate, Scale',
|
|
description: "rotate: '30deg', scaleX: 2, scaleY: 2",
|
|
render(): Node {
|
|
return (
|
|
<View style={styles.container}>
|
|
<View style={styles.box3step2} />
|
|
</View>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
title: 'Rotate, Scale, Translate ',
|
|
description:
|
|
"rotate: '30deg', scaleX: 2, scaleY: 2, translateX: 100, translateY: 50",
|
|
render(): Node {
|
|
return (
|
|
<View style={styles.container}>
|
|
<View style={styles.box3step3} />
|
|
</View>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
title: 'Translate, Scale, Rotate',
|
|
description: "translate: [200, 350], scale: 2.5, rotate: '-0.2rad'",
|
|
render(): Node {
|
|
return (
|
|
<View style={styles.container}>
|
|
<View style={styles.box4} />
|
|
</View>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
title: 'Translate, Rotate, Scale',
|
|
description: "translate: [-50, 35], rotate: '50deg', scale: 2",
|
|
render(): Node {
|
|
return (
|
|
<View style={styles.container}>
|
|
<View style={[styles.box5, styles.box5Transform]} />
|
|
</View>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
title: 'Amimate Translate single prop',
|
|
description: "rotate: '360deg'",
|
|
render(): Node {
|
|
return <AnimateTansformSingleProp />;
|
|
},
|
|
},
|
|
];
|