-
Notifications
You must be signed in to change notification settings - Fork 24.5k
/
Copy pathTextInlineView.js
205 lines (192 loc) · 4.96 KB
/
TextInlineView.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/**
* 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';
const React = require('react');
const {Image, Text, TouchableHighlight, View} = require('react-native');
function Basic() {
return (
<Text>
This text contains an inline blue view{' '}
<View style={{width: 25, height: 25, backgroundColor: 'steelblue'}} /> and
an inline image <Image source={require('../flux.png')} />. Neat, huh?
</Text>
);
}
function ClippedByText() {
return (
<View>
{/*
* Inline View
**/}
<Text>
The <Text style={{fontWeight: 'bold'}}>inline view</Text> below is
taller than its Text parent and should be clipped.
</Text>
<Text
style={{
overflow: 'hidden',
width: 150,
height: 75,
backgroundColor: 'lightgrey',
}}>
This is an inline view
{/* Render a red border around the steelblue rectangle to make it clear how the inline view is being clipped */}
<View style={{width: 50, height: 100, backgroundColor: 'red'}}>
<View
style={{
width: 48,
height: 98,
left: 1,
top: 1,
backgroundColor: 'steelblue',
}}
/>
</View>
</Text>
{/*
* Inline Image
**/}
<Text style={{marginTop: 10}}>
The <Text style={{fontWeight: 'bold'}}>inline image</Text> below is
taller than its Text parent and should be clipped.
</Text>
<Text
style={{
overflow: 'hidden',
width: 175,
height: 100,
backgroundColor: 'lightgrey',
}}>
This is an inline image
<Image
source={{
uri: 'https://picsum.photos/100',
width: 50,
height: 100,
}}
style={{
width: 50,
height: 100,
}}
/>
</Text>
</View>
);
}
type ChangeSizeState = {|
width: number,
|};
class ChangeImageSize extends React.Component<*, ChangeSizeState> {
state = {
width: 50,
};
render() {
return (
<View>
<TouchableHighlight
onPress={() => {
this.setState({width: this.state.width === 50 ? 100 : 50});
}}>
<Text style={{fontSize: 15}}>
Change Image Width (width={this.state.width})
</Text>
</TouchableHighlight>
<Text>
This is an
<Image
source={{
uri: 'https://picsum.photos/50',
width: this.state.width,
height: 50,
}}
style={{
width: this.state.width,
height: 50,
}}
/>
inline image
</Text>
</View>
);
}
}
class ChangeViewSize extends React.Component<*, ChangeSizeState> {
state = {
width: 50,
};
render() {
return (
<View>
<TouchableHighlight
onPress={() => {
this.setState({width: this.state.width === 50 ? 100 : 50});
}}>
<Text style={{fontSize: 15}}>
Change View Width (width={this.state.width})
</Text>
</TouchableHighlight>
<Text>
This is an
<View
style={{
width: this.state.width,
height: 50,
backgroundColor: 'steelblue',
}}
/>
inline view
</Text>
</View>
);
}
}
class ChangeInnerViewSize extends React.Component<*, ChangeSizeState> {
state = {
width: 50,
};
render() {
return (
<View>
<TouchableHighlight
onPress={() => {
this.setState({width: this.state.width === 50 ? 100 : 50});
}}>
{/* When updating `state.width`, it's important that the only thing that
changes is the width of the pink inline view. When we do this, we
demonstrate a bug in RN Android where the pink view doesn't get
rerendered and remains at its old size. If other things change
(e.g. we display `state.width` as text somewhere) it could circumvent
the bug and cause the pink view to be rerendered at its new size. */}
<Text style={{fontSize: 15}}>Change Pink View Width</Text>
</TouchableHighlight>
<Text>
This is an
<View style={{width: 125, height: 75, backgroundColor: 'steelblue'}}>
<View
style={{
width: this.state.width,
height: 50,
backgroundColor: 'pink',
}}
/>
</View>
inline view
</Text>
</View>
);
}
}
module.exports = {
Basic,
ClippedByText,
ChangeImageSize,
ChangeViewSize,
ChangeInnerViewSize,
};