Skip to content

Commit ba1b779

Browse files
jasozhfacebook-github-bot
authored andcommitted
Fix CloseButton alignment in KeyboardAvoidingViewExample (#58431)
Summary: The RNTester KeyboardAvoidingView example had alignment issues with the close button on top of the example form. When KeyboardAvoidingView's behavior was toggled to "position", a small amount of right padding is added to the close button, making it appear non-flush with the right edge of the form. This impacted both the "Keyboard Avoiding View with different behaviors" screen and the "Keyboard Avoiding View with contentContainerStyle" screen. Changelog: [Internal] Differential Revision: D119204438
1 parent dab6c85 commit ba1b779

1 file changed

Lines changed: 13 additions & 27 deletions

File tree

‎packages/rn-tester/js/examples/KeyboardAvoidingView/KeyboardAvoidingViewExample.js‎

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,13 @@ const TextInputForm = () => {
4747
);
4848
};
4949

50-
const CloseButton = (
51-
props:
52-
{behavior: any, setModalOpen: any} | {behavior: string, setModalOpen: any},
53-
) => {
50+
const CloseButton = (props: {setModalOpen: boolean => void}) => {
5451
return (
55-
<View
56-
style={[
57-
styles.closeView,
58-
{marginHorizontal: props.behavior === 'position' ? 0 : 25},
59-
]}>
60-
<Pressable
61-
onPress={() => props.setModalOpen(false)}
62-
style={styles.closeButton}>
63-
<Text style={styles.touchableText}>Close</Text>
64-
</Pressable>
65-
</View>
52+
<Pressable
53+
onPress={() => props.setModalOpen(false)}
54+
style={styles.closeButton}>
55+
<Text style={styles.touchableText}>Close</Text>
56+
</Pressable>
6657
);
6758
};
6859

@@ -114,7 +105,7 @@ const KeyboardAvoidingViewBehaviour = () => {
114105
</Text>
115106
</TouchableOpacity>
116107
</View>
117-
<CloseButton behavior={behavior} setModalOpen={setModalOpen} />
108+
<CloseButton setModalOpen={setModalOpen} />
118109
<TextInputForm />
119110
</KeyboardAvoidingView>
120111
</Modal>
@@ -140,7 +131,7 @@ const KeyboardAvoidingDisabled = () => {
140131
enabled={false}
141132
behavior={'height'}
142133
style={styles.container}>
143-
<CloseButton behavior={'height'} setModalOpen={setModalOpen} />
134+
<CloseButton setModalOpen={setModalOpen} />
144135
<TextInputForm />
145136
</KeyboardAvoidingView>
146137
</Modal>
@@ -162,7 +153,7 @@ const KeyboardAvoidingVerticalOffset = () => {
162153
keyboardVerticalOffset={20}
163154
behavior={'padding'}
164155
style={styles.container}>
165-
<CloseButton behavior={'height'} setModalOpen={setModalOpen} />
156+
<CloseButton setModalOpen={setModalOpen} />
166157
<TextInputForm />
167158
</KeyboardAvoidingView>
168159
</Modal>
@@ -185,7 +176,7 @@ const KeyboardAvoidingContentContainerStyle = () => {
185176
behavior={'position'}
186177
style={styles.container}
187178
contentContainerStyle={styles.contentContainer}>
188-
<CloseButton behavior={'height'} setModalOpen={setModalOpen} />
179+
<CloseButton setModalOpen={setModalOpen} />
189180
<TextInputForm />
190181
</KeyboardAvoidingView>
191182
</Modal>
@@ -205,9 +196,9 @@ const styles = StyleSheet.create({
205196
container: {
206197
flex: 1,
207198
justifyContent: 'center',
208-
alignItems: 'center',
209-
paddingHorizontal: 20,
210199
paddingTop: 20,
200+
width: 300,
201+
alignSelf: 'center',
211202
},
212203
contentContainer: {
213204
paddingTop: 20,
@@ -217,13 +208,9 @@ const styles = StyleSheet.create({
217208
borderRadius: 5,
218209
borderWidth: 1,
219210
height: 44,
220-
width: 300,
221211
marginBottom: 20,
222212
paddingHorizontal: 10,
223213
},
224-
closeView: {
225-
alignSelf: 'stretch',
226-
},
227214
pillStyle: {
228215
padding: 10,
229216
marginHorizontal: 5,
@@ -233,8 +220,7 @@ const styles = StyleSheet.create({
233220
borderColor: 'blue',
234221
},
235222
closeButton: {
236-
flexDirection: 'row',
237-
justifyContent: 'flex-end',
223+
alignSelf: 'flex-end',
238224
marginVertical: 10,
239225
padding: 10,
240226
},

0 commit comments

Comments
 (0)