From bc5083ac40b269169522fa4e4acca17e26c17213 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Wed, 18 Oct 2017 19:30:02 -0700 Subject: [PATCH] Add examples to RTLExample Reviewed By: sahrens Differential Revision: D5929933 fbshipit-source-id: 16ef86c4ab444f740b2568ddb3af0ffd5ff0d02b --- RNTester/js/RTLExample.js | 410 +++++++++++++++++++++++++++++++------- 1 file changed, 342 insertions(+), 68 deletions(-) diff --git a/RNTester/js/RTLExample.js b/RNTester/js/RTLExample.js index cde83d090..c7cf4930b 100644 --- a/RNTester/js/RTLExample.js +++ b/RNTester/js/RTLExample.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @flow + * @format * @providesModule RTLExample */ 'use strict'; @@ -26,10 +27,10 @@ const { TouchableWithoutFeedback, Switch, View, + Button, } = ReactNative; const Platform = require('Platform'); - const RNTesterPage = require('./RNTesterPage'); const RNTesterBlock = require('./RNTesterBlock'); @@ -48,57 +49,46 @@ const IMAGE_SIZE = [IMAGE_DIMENSION, IMAGE_DIMENSION]; const IS_RTL = I18nManager.isRTL; function ListItem(props) { - return ( + return ( - - - - - - - Text - Text - Text - - - - - - - Button - - - - - ); + + + + + + Text Text Text + + + + + Button + + + + ); } function TextAlignmentExample(props) { return ( - - - - Left-to-Right language without text alignment. - - - {'\u0645\u0646 \u0627\u0644\u064A\u0645\u064A\u0646 ' + - '\u0625\u0644\u0649 \u0627\u0644\u064A\u0633\u0627\u0631 ' + - '\u0627\u0644\u0644\u063A\u0629 \u062F\u0648\u0646 ' + - '\u0645\u062D\u0627\u0630\u0627\u0629 \u0627\u0644\u0646\u0635'} - - - {'\u05DE\u05D9\u05DE\u05D9\u05DF \u05DC\u05E9\u05DE\u05D0\u05DC ' + - '\u05D4\u05E9\u05E4\u05D4 \u05D1\u05DC\u05D9 ' + - '\u05D9\u05D9\u05E9\u05D5\u05E8 \u05D8\u05E7\u05E1\u05D8'} - - - - ); + + + + Left-to-Right language without text alignment. + + + {'\u0645\u0646 \u0627\u0644\u064A\u0645\u064A\u0646 ' + + '\u0625\u0644\u0649 \u0627\u0644\u064A\u0633\u0627\u0631 ' + + '\u0627\u0644\u0644\u063A\u0629 \u062F\u0648\u0646 ' + + '\u0645\u062D\u0627\u0630\u0627\u0629 \u0627\u0644\u0646\u0635'} + + + {'\u05DE\u05D9\u05DE\u05D9\u05DF \u05DC\u05E9\u05DE\u05D0\u05DC ' + + '\u05D4\u05E9\u05E4\u05D4 \u05D1\u05DC\u05D9 ' + + '\u05D9\u05D9\u05E9\u05D5\u05E8 \u05D8\u05E7\u05E1\u05D8'} + + + + ); } function AnimationBlock(props) { @@ -114,6 +104,276 @@ function AnimationBlock(props) { ); } +type RTLSwitcherComponentState = {| + isRTL: boolean, +|}; + +function withRTLState(Component) { + return class extends React.Component<*, RTLSwitcherComponentState> { + constructor(...args) { + super(...args); + this.state = { + isRTL: IS_RTL, + }; + } + + render() { + const setRTL = isRTL => this.setState({isRTL: isRTL}); + return ; + } + }; +} + +const RTLToggler = ({isRTL, setRTL}) => { + if (Platform.OS === 'android') { + return {isRTL ? 'RTL' : 'LTR'}; + } + + const toggleRTL = () => setRTL(!isRTL); + return ( +