Skip to content

Commit ec673d0

Browse files
sherginfacebook-github-bot
authored andcommitted
Added support of direction style property
Summary: Now layout direction (LTR or LTR) can be specified not only for whole app but also for view subtree via `direction` style property. Reviewed By: mmmulani Differential Revision: D4510206 fbshipit-source-id: 4e56c5886b6e42f2343165eb76be897e681c5ba4
1 parent d73f7d3 commit ec673d0

File tree

14 files changed

+95
-48
lines changed

14 files changed

+95
-48
lines changed
Loading
Loading
Loading
Loading
Loading

Examples/UIExplorer/UIExplorerIntegrationTests/UIExplorerSnapshotTests.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ - (void)test##name \
4343

4444
RCT_TEST(ViewExample)
4545
RCT_TEST(LayoutExample)
46+
RCT_TEST(ScrollViewExample)
4647
RCT_TEST(TextExample)
4748
#if !TARGET_OS_TV
4849
// No switch or slider available on tvOS

Examples/UIExplorer/js/ScrollViewExample.js

Lines changed: 65 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var {
3333
Image
3434
} = ReactNative;
3535

36-
exports.displayName = (undefined: ?string);
36+
exports.displayName = 'ScrollViewExample';
3737
exports.title = '<ScrollView>';
3838
exports.description = 'Component that enables scrolling through child components';
3939
exports.examples = [
@@ -50,7 +50,7 @@ exports.examples = [
5050
onScroll={() => { console.log('onScroll!'); }}
5151
scrollEventThrottle={200}
5252
style={styles.scrollView}>
53-
{THUMBS.map(createThumbRow)}
53+
{THUMB_URLS.map(createThumbRow)}
5454
</ScrollView>
5555
<TouchableOpacity
5656
style={styles.button}
@@ -69,26 +69,37 @@ exports.examples = [
6969
title: '<ScrollView> (horizontal = true)',
7070
description: 'You can display <ScrollView>\'s child components horizontally rather than vertically',
7171
render: function() {
72-
var _scrollView: ScrollView;
72+
73+
function renderScrollView(title: string, addtionalStyles: StyleSheet) {
74+
var _scrollView: ScrollView;
75+
return (
76+
<View style={addtionalStyles}>
77+
<Text style={styles.text}>{title}</Text>
78+
<ScrollView
79+
ref={(scrollView) => { _scrollView = scrollView; }}
80+
automaticallyAdjustContentInsets={false}
81+
horizontal={true}
82+
style={[styles.scrollView, styles.horizontalScrollView]}>
83+
{THUMB_URLS.map(createThumbRow)}
84+
</ScrollView>
85+
<TouchableOpacity
86+
style={styles.button}
87+
onPress={() => { _scrollView.scrollTo({x: 0}); }}>
88+
<Text>Scroll to start</Text>
89+
</TouchableOpacity>
90+
<TouchableOpacity
91+
style={styles.button}
92+
onPress={() => { _scrollView.scrollToEnd({animated: true}); }}>
93+
<Text>Scroll to end</Text>
94+
</TouchableOpacity>
95+
</View>
96+
);
97+
}
98+
7399
return (
74100
<View>
75-
<ScrollView
76-
ref={(scrollView) => { _scrollView = scrollView; }}
77-
automaticallyAdjustContentInsets={false}
78-
horizontal={true}
79-
style={[styles.scrollView, styles.horizontalScrollView]}>
80-
{THUMBS.map(createThumbRow)}
81-
</ScrollView>
82-
<TouchableOpacity
83-
style={styles.button}
84-
onPress={() => { _scrollView.scrollTo({x: 0}); }}>
85-
<Text>Scroll to start</Text>
86-
</TouchableOpacity>
87-
<TouchableOpacity
88-
style={styles.button}
89-
onPress={() => { _scrollView.scrollToEnd({animated: true}); }}>
90-
<Text>Scroll to end</Text>
91-
</TouchableOpacity>
101+
{renderScrollView('LTR layout', {direction: 'ltr'})}
102+
{renderScrollView('RTL layout', {direction: 'rtl'})}
92103
</View>
93104
);
94105
}
@@ -101,49 +112,59 @@ class Thumb extends React.Component {
101112

102113
render() {
103114
return (
104-
<View style={styles.button}>
105-
<Image style={styles.img} source={{uri:this.props.uri}} />
115+
<View style={styles.thumb}>
116+
<Image style={styles.img} source={this.props.source} />
106117
</View>
107118
);
108119
}
109120
}
110121

111-
var THUMBS = ['https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-ash3/t39.1997/p128x128/851549_767334479959628_274486868_n.png', 'https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-prn1/t39.1997/p128x128/851561_767334496626293_1958532586_n.png', 'https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-ash3/t39.1997/p128x128/851579_767334503292959_179092627_n.png', 'https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-prn1/t39.1997/p128x128/851589_767334513292958_1747022277_n.png', 'https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-prn1/t39.1997/p128x128/851563_767334559959620_1193692107_n.png', 'https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-prn1/t39.1997/p128x128/851593_767334566626286_1953955109_n.png', 'https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-prn1/t39.1997/p128x128/851591_767334523292957_797560749_n.png', 'https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-prn1/t39.1997/p128x128/851567_767334529959623_843148472_n.png', 'https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-prn1/t39.1997/p128x128/851548_767334489959627_794462220_n.png', 'https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-prn1/t39.1997/p128x128/851575_767334539959622_441598241_n.png', 'https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-ash3/t39.1997/p128x128/851573_767334549959621_534583464_n.png', 'https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-prn1/t39.1997/p128x128/851583_767334573292952_1519550680_n.png'];
112-
THUMBS = THUMBS.concat(THUMBS); // double length of THUMBS
113-
var createThumbRow = (uri, i) => <Thumb key={i} uri={uri} />;
122+
var THUMB_URLS = [
123+
require('./Thumbnails/like.png'),
124+
require('./Thumbnails/dislike.png'),
125+
require('./Thumbnails/call.png'),
126+
require('./Thumbnails/fist.png'),
127+
require('./Thumbnails/bandaged.png'),
128+
require('./Thumbnails/flowers.png'),
129+
require('./Thumbnails/heart.png'),
130+
require('./Thumbnails/liking.png'),
131+
require('./Thumbnails/party.png'),
132+
require('./Thumbnails/poke.png'),
133+
require('./Thumbnails/superlike.png'),
134+
require('./Thumbnails/victory.png'),
135+
];
136+
137+
THUMB_URLS = THUMB_URLS.concat(THUMB_URLS); // double length of THUMB_URLS
138+
139+
var createThumbRow = (uri, i) => <Thumb key={i} source={uri} />;
114140

115141
var styles = StyleSheet.create({
116142
scrollView: {
117-
backgroundColor: '#6A85B1',
143+
backgroundColor: '#eeeeee',
118144
height: 300,
119145
},
120146
horizontalScrollView: {
121-
height: 120,
122-
},
123-
containerPage: {
124-
height: 50,
125-
width: 50,
126-
backgroundColor: '#527FE4',
127-
padding: 5,
147+
height: 106,
128148
},
129149
text: {
130-
fontSize: 20,
131-
color: '#888888',
132-
left: 80,
133-
top: 20,
134-
height: 40,
150+
fontSize: 16,
151+
fontWeight: 'bold',
152+
margin: 5,
153+
textAlign: 'left',
135154
},
136155
button: {
137-
margin: 7,
156+
margin: 5,
138157
padding: 5,
139158
alignItems: 'center',
140-
backgroundColor: '#eaeaea',
159+
backgroundColor: '#cccccc',
141160
borderRadius: 3,
142161
},
143-
buttonContents: {
144-
flexDirection: 'row',
145-
width: 64,
146-
height: 64,
162+
thumb: {
163+
margin: 5,
164+
padding: 5,
165+
backgroundColor: '#cccccc',
166+
borderRadius: 3,
167+
minWidth: 96,
147168
},
148169
img: {
149170
width: 64,

Libraries/StyleSheet/LayoutPropTypes.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,18 @@ var LayoutPropTypes = {
470470
* more details.
471471
*/
472472
zIndex: ReactPropTypes.number,
473+
474+
/** `direction` specifies the directional flow of the user interface.
475+
* The default is `inherit`, except for root node which will have
476+
* value based on the current locale.
477+
* See https://facebook.github.io/yoga/docs/rtl/
478+
* for more details.
479+
*/
480+
direction: ReactPropTypes.oneOf([
481+
'inherit',
482+
'ltr',
483+
'rtl',
484+
]),
473485
};
474486

475487
module.exports = LayoutPropTypes;

React/Base/RCTConvert.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ typedef BOOL css_backface_visibility_t;
118118
+ (YGAlign)YGAlign:(id)json;
119119
+ (YGPositionType)YGPositionType:(id)json;
120120
+ (YGWrap)YGWrap:(id)json;
121+
+ (YGDirection)YGDirection:(id)json;
121122

122123
+ (RCTPointerEvents)RCTPointerEvents:(id)json;
123124
+ (RCTAnimationType)RCTAnimationType:(id)json;

React/Base/RCTConvert.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,12 @@ + (NSPropertyList)NSPropertyList:(id)json
667667
@"baseline": @(YGAlignBaseline)
668668
}), YGAlignFlexStart, intValue)
669669

670+
RCT_ENUM_CONVERTER(YGDirection, (@{
671+
@"inherit": @(YGDirectionInherit),
672+
@"ltr": @(YGDirectionLTR),
673+
@"rtl": @(YGDirectionRTL),
674+
}), YGDirectionInherit, intValue)
675+
670676
RCT_ENUM_CONVERTER(YGPositionType, (@{
671677
@"absolute": @(YGPositionTypeAbsolute),
672678
@"relative": @(YGPositionTypeRelative)

0 commit comments

Comments
 (0)