Skip to content

Commit 6c68db9

Browse files
jasozhfacebook-github-bot
authored andcommitted
Add direction style example in RTLExample
Summary: Add a new RNTester example in RTLExample that reproduces the issue where toggling the direction style fails to update border radius on Android. Changelog: [Internal] Differential Revision: D132253189
1 parent 94367fe commit 6c68db9

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

‎packages/rn-tester/js/examples/RTL/RTLExample.js‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
'use strict';
1212

1313
import type {RNTesterModuleExample} from '../../types/RNTesterTypes';
14+
import type {StyleProp, ViewStyle} from 'react-native';
1415

1516
import RNTexterText from '../../components/RNTesterText';
1617
import * as React from 'react';
18+
import {useState} from 'react';
1719
import {
1820
Alert,
1921
Animated,
@@ -22,6 +24,7 @@ import {
2224
Image,
2325
PixelRatio,
2426
Platform,
27+
Pressable,
2528
StyleSheet,
2629
Switch,
2730
Text,
@@ -594,6 +597,60 @@ const BorderExample = withRTLState(({isRTL, setRTL}) => {
594597
);
595598
});
596599

600+
component DirectionExample() {
601+
const [direction, setDirection] = useState<'ltr' | 'rtl'>('ltr');
602+
return (
603+
<View>
604+
<Button
605+
onPress={() => setDirection(d => (d === 'ltr' ? 'rtl' : 'ltr'))}
606+
title={`direction: ${direction}`}
607+
color="gray"
608+
accessibilityLabel="Toggle direction style"
609+
/>
610+
<View style={{direction}}>
611+
<DirectionBox
612+
label="backgroundColor"
613+
style={{backgroundColor: '#ddd'}}
614+
/>
615+
<DirectionBox
616+
label="border (start: red, end: green)"
617+
style={{
618+
borderEndColor: 'green',
619+
borderStartColor: 'red',
620+
borderWidth: 6,
621+
}}
622+
/>
623+
<DirectionBox
624+
label="backgroundImage"
625+
style={{
626+
backgroundImage: 'linear-gradient(90deg, #e66465, #9198e5)',
627+
}}
628+
/>
629+
{Platform.OS === 'android' && (
630+
<DirectionBox label="elevation (Android)" style={{elevation: 2}} />
631+
)}
632+
{Platform.OS === 'android' && (
633+
<Pressable
634+
android_ripple={{color: 'red', borderless: false}}
635+
style={[styles.directionStyleBox, {backgroundColor: '#ddd'}]}>
636+
<RNTexterText style={{textAlign: 'center'}}>
637+
ripple (Android)
638+
</RNTexterText>
639+
</Pressable>
640+
)}
641+
</View>
642+
</View>
643+
);
644+
}
645+
646+
component DirectionBox(label: string, style?: StyleProp<ViewStyle>) {
647+
return (
648+
<View style={[styles.directionStyleBox, style]}>
649+
<RNTexterText style={{textAlign: 'center'}}>{label}</RNTexterText>
650+
</View>
651+
);
652+
}
653+
597654
const directionStyle = (isRTL: boolean) =>
598655
Platform.OS !== 'android' ? {direction: isRTL ? 'rtl' : 'ltr'} : null;
599656

@@ -708,6 +765,13 @@ const styles = StyleSheet.create({
708765
bold: {
709766
fontWeight: 'bold',
710767
},
768+
directionStyleBox: {
769+
alignItems: 'center',
770+
borderTopStartRadius: 30,
771+
height: 60,
772+
justifyContent: 'center',
773+
marginTop: 8,
774+
},
711775
rtlToggler: {
712776
color: 'gray',
713777
padding: 8,
@@ -832,4 +896,13 @@ exports.examples = [
832896
return <BorderExample />;
833897
},
834898
},
899+
{
900+
title: 'Direction Style',
901+
description:
902+
("A view's 'direction' style sets the layout direction for it and its " +
903+
"children, independent of the app's RTL setting.") as string,
904+
render: function (): React.MixedElement {
905+
return <DirectionExample />;
906+
},
907+
},
835908
] as Array<RNTesterModuleExample>;

0 commit comments

Comments
 (0)