mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Fix InputAccessoryView example in dark mode and convert to functional components (#51583)
Summary: As I reviewed some examples, I noticed that this one's dark mode could be improved, and the code could be modernised a bit as well by converting its classes into functional components. ## Changelog: [INTERNAL] - Fix InputAccessoryView example in dark mode and convert to functional components Pull Request resolved: https://github.com/facebook/react-native/pull/51583 Test Plan: <details> <summary>Screenshots</summary> | Dark | Light | |--------|-------| |  |  | </details> Reviewed By: fabriziocucci Differential Revision: D75404561 Pulled By: cortinico fbshipit-source-id: 3318e9869919e99055e47b59c89de0b22976f142
This commit is contained in:
1 parent
c62d9527b4
commit
9218d1ed89
1 file changed
+49
-56
@@ -10,8 +10,9 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const React = require('react');
|
||||
const {
|
||||
import {useTheme} from '../../components/RNTesterTheme';
|
||||
import {useState} from 'react';
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
InputAccessoryView,
|
||||
@@ -20,66 +21,59 @@ const {
|
||||
Text,
|
||||
TextInput,
|
||||
View,
|
||||
} = require('react-native');
|
||||
} from 'react-native';
|
||||
|
||||
type MessageProps = $ReadOnly<{}>;
|
||||
class Message extends React.PureComponent<MessageProps> {
|
||||
render(): React.Node {
|
||||
return (
|
||||
<View style={styles.textBubbleBackground}>
|
||||
<Text style={styles.text}>Text Message</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
function Message(): React.Node {
|
||||
return (
|
||||
<View style={styles.textBubbleBackground}>
|
||||
<Text style={styles.text}>Text Message</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
type TextInputProps = $ReadOnly<{}>;
|
||||
type TextInputState = {text: string};
|
||||
class TextInputBar extends React.PureComponent<TextInputProps, TextInputState> {
|
||||
state: TextInputState = {text: ''};
|
||||
function TextInputBar(): React.Node {
|
||||
const {PlaceholderTextColor, LabelColor, SeparatorColor} = useTheme();
|
||||
const [text, setText] = useState<string>('');
|
||||
|
||||
render(): React.Node {
|
||||
return (
|
||||
<View style={styles.textInputContainer}>
|
||||
<TextInput
|
||||
style={styles.textInput}
|
||||
onChangeText={text => {
|
||||
this.setState({text});
|
||||
}}
|
||||
value={this.state.text}
|
||||
placeholder={'Type a message...'}
|
||||
/>
|
||||
<Button
|
||||
onPress={() => {
|
||||
Alert.alert('You tapped the button!');
|
||||
}}
|
||||
title="Send"
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<View style={[styles.textInputContainer, {borderTopColor: SeparatorColor}]}>
|
||||
<TextInput
|
||||
style={[styles.textInput, {color: LabelColor}]}
|
||||
onChangeText={setText}
|
||||
value={text}
|
||||
placeholder={'Type a message...'}
|
||||
placeholderTextColor={PlaceholderTextColor}
|
||||
/>
|
||||
<Button
|
||||
onPress={() => {
|
||||
Alert.alert('You tapped the button!');
|
||||
}}
|
||||
title="Send"
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
function InputAccessoryViewExample(): React.Node {
|
||||
const {BackgroundColor} = useTheme();
|
||||
|
||||
return (
|
||||
<>
|
||||
<ScrollView style={styles.fill} keyboardDismissMode="interactive">
|
||||
{Array(15)
|
||||
.fill()
|
||||
.map((_, i) => (
|
||||
<Message key={i} />
|
||||
))}
|
||||
</ScrollView>
|
||||
<InputAccessoryView backgroundColor={BackgroundColor}>
|
||||
<TextInputBar />
|
||||
</InputAccessoryView>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
const BAR_HEIGHT = 44;
|
||||
type InputAccessoryProps = $ReadOnly<{}>;
|
||||
class InputAccessoryViewExample extends React.Component<InputAccessoryProps> {
|
||||
render(): React.Node {
|
||||
return (
|
||||
<>
|
||||
<ScrollView style={styles.fill} keyboardDismissMode="interactive">
|
||||
{Array(15)
|
||||
.fill()
|
||||
.map((_, i) => (
|
||||
<Message key={i} />
|
||||
))}
|
||||
</ScrollView>
|
||||
<InputAccessoryView backgroundColor="#fffffff7">
|
||||
<TextInputBar />
|
||||
</InputAccessoryView>
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
fill: {
|
||||
@@ -89,7 +83,6 @@ const styles = StyleSheet.create({
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
borderTopWidth: 1,
|
||||
borderTopColor: '#eee',
|
||||
height: BAR_HEIGHT,
|
||||
},
|
||||
textInput: {
|
||||
|
||||
Reference in new issue
Block a user