From b0302eca2463a6eac1ea0bd18958d37afdcaa9d4 Mon Sep 17 00:00:00 2001 From: Josh Justice Date: Mon, 28 Jan 2019 03:15:14 -0800 Subject: [PATCH] Separate MaskedViewExample into individual examples (#23168) Summary: In RNTester, previously the MaskedViewExample was returned as a single example record. However, within that one example there were several sub-examples. Now that we've implemented example filtering, filtering didn't really work for MaskedViewExample because it only operates on top-level examples. There was no benefit to grouping MaskedViewExample into a single example, so this PR splits it into separate examples. Changelog: ---------- Help reviewers and the release process by writing your own changelog entry. See http://facebook.github.io/react-native/docs/contributing#changelog for an example. [General] [Fixed] - Fix filtering of MaskedViewExample by splitting into separate example records. Pull Request resolved: https://github.com/facebook/react-native/pull/23168 Differential Revision: D13838524 Pulled By: cpojer fbshipit-source-id: 21ae8228e4ce5bfc06fb1ea230163da9261cb36a --- RNTester/js/MaskedViewExample.js | 259 ++++++++++++++++++------------- 1 file changed, 148 insertions(+), 111 deletions(-) diff --git a/RNTester/js/MaskedViewExample.js b/RNTester/js/MaskedViewExample.js index 5516a68ff..238a22c7d 100644 --- a/RNTester/js/MaskedViewExample.js +++ b/RNTester/js/MaskedViewExample.js @@ -11,8 +11,6 @@ 'use strict'; const React = require('react'); -const RNTesterBlock = require('RNTesterBlock'); -const RNTesterPage = require('RNTesterPage'); const { Animated, Image, @@ -23,25 +21,15 @@ const { } = require('react-native'); type Props = $ReadOnly<{||}>; -type State = {| +type ChangingChildrenState = {| alternateChildren: boolean, |}; -class MaskedViewExample extends React.Component { - state = { - alternateChildren: true, - }; - +class AnimatedMaskExample extends React.Component { _maskRotateAnimatedValue = new Animated.Value(0); _maskScaleAnimatedValue = new Animated.Value(1); componentDidMount() { - setInterval(() => { - this.setState(state => ({ - alternateChildren: !state.alternateChildren, - })); - }, 1000); - Animated.loop( Animated.sequence([ Animated.timing(this._maskScaleAnimatedValue, { @@ -68,107 +56,87 @@ class MaskedViewExample extends React.Component { render() { return ( - - - - - Basic Mask - - }> - - - - - - - + + Basic Mask + + }> + - - - - }> - - - - - - - - - - Basic Mask - - }> - - - - - - - - - - - Basic Mask - - }> - {this.state.alternateChildren - ? [ - , - , - ] - : null} - - - - + + + + + + ); + } +} + +class ChangingChildrenMaskExample extends React.Component< + Props, + ChangingChildrenState, +> { + state = { + alternateChildren: true, + }; + + componentDidMount() { + setInterval(() => { + this.setState(state => ({ + alternateChildren: !state.alternateChildren, + })); + }, 1000); + } + + render() { + return ( + + + Basic Mask + + }> + {this.state.alternateChildren + ? [ + , + , + ] + : null} + + ); } } const styles = StyleSheet.create({ + exampleWrapperStyle: { + width: 340, + height: 300, + alignSelf: 'center', + }, + imageStyle: { + height: 200, + width: 200, + }, maskContainerStyle: { flex: 1, backgroundColor: 'transparent', @@ -180,6 +148,20 @@ const styles = StyleSheet.create({ fontSize: 40, fontWeight: 'bold', }, + blueStyle: { + flex: 1, + backgroundColor: 'blue', + }, + redStyle: { + flex: 1, + backgroundColor: 'red', + }, + grayStyle: { + backgroundColor: '#eeeeee', + }, + flexStyle: { + flex: 1, + }, }); exports.title = ''; @@ -187,9 +169,64 @@ exports.description = 'Renders the child view with a mask specified in the `renderMask` prop.'; exports.examples = [ { - title: 'Simple masked view', - render: function(): React.Element { - return ; + title: 'Basic Mask', + render: function(): React.Element { + return ( + + + Basic Mask + + }> + + + + + ); + }, + }, + { + title: 'Image Mask', + render: function(): React.Element { + return ( + + + + + }> + + + + + + ); + }, + }, + { + title: 'Animated Mask', + render: function(): React.Element { + return ; + }, + }, + { + title: 'Mask w/ Changing Children', + render: function(): React.Element { + return ; }, }, ];