Skip to content

Commit c8d017f

Browse files
authored
Infra/keyboard input view refactor 3 (#664)
* Remove two exports * Change from TouchableOpacity to Button * CustomKeyboardView into two files (iOS and Android) * TextInputKeyboardManager into two files (iOS and Android) (cherry picked from commit 1b4aa99) * Remove logger (cherry picked from commit b5385c8) * Refactor - move keyboard related import under Keyboard * Move docs to correct location (cherry picked from commit cfbc9c1) * Refactor - bind into -> (cherry picked from commit 760812f) * onToggleExpandedKeyboard is iOS only (cherry picked from commit 4bc5cfc) * Refactor KeyboardView * KeyboardInputViewScreen refactor some styles etc (cherry picked from commit eee22fc) * onToggleExpandedKeyboard is iOS only (part 2) (cherry picked from commit 95631b8) * KeyboardTrackingViewScreen refactor some styles etc (cherry picked from commit 63b2312) * Remove duplicated code (cherry picked from commit cdc3cee) * Mostly prettify (cherry picked from commit 07b975b) * Remove unused import (cherry picked from commit 31a8097) * Fix broken screen links (and remove guidelines references) (cherry picked from commit a45a0fb) * Remove unused import (cherry picked from commit 982ea01) * Add documentation for KeyboardAwareInsetsView (cherry picked from commit 6f3bfe6) * Refactor (this.props) (cherry picked from commit fc110bf) * Refactor (this.state) (cherry picked from commit 41f7f8d) * Add most of the docs (cherry picked from commit 47bc86d) * Remove navigation for android (cherry picked from commit 8fc87e2) * Add example for onRequestShowKeyboard and requestShowKeyboard (cherry picked from commit adf3a71) * Remove usage of toggleExpandedKeyboard and prettify (cherry picked from commit 56c1232) * Complete docs (cherry picked from commit ded2e11) * Fix some docs (cherry picked from commit f2402fa) * Move iOS scroll behaviour to JS enum (from native module) (cherry picked from commit 7a219d4)
1 parent c3de446 commit c8d017f

39 files changed

+821
-822
lines changed

demo/src/screens/componentScreens/TextFieldScreen/InputsScreen.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import {
1010
TextArea,
1111
Modal,
1212
Button,
13-
KeyboardAwareInsetsView
13+
Keyboard
1414
} from 'react-native-ui-lib'; //eslint-disable-line
15-
15+
const KeyboardAwareInsetsView = Keyboard.KeyboardAwareInsetsView;
1616

1717
const richText = require('../../../assets/icons/richText.png');
1818
const dropDown = require('../../../assets/icons/chevronDown.png');

demo/src/screens/nativeComponentScreens/KeyboardTrackingViewScreen.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import React, {PureComponent} from 'react';
22
import {ScrollView, StyleSheet} from 'react-native';
33
import {
4+
Keyboard,
45
Text,
56
View,
6-
KeyboardTrackingView,
77
TextField,
88
Image,
99
Colors,
10-
Spacings,
1110
Switch,
1211
Constants
1312
} from 'react-native-ui-lib';
13+
const KeyboardTrackingView = Keyboard.KeyboardTrackingView;
1414

1515
const URIs = [
1616
{
@@ -41,7 +41,7 @@ export default class KeyboardTrackingViewScreen extends PureComponent {
4141
const {trackInteractive} = this.state;
4242

4343
return (
44-
<View style={styles.container}>
44+
<View flex bg-dark80>
4545
<ScrollView
4646
contentContainerStyle={styles.scrollContainer}
4747
keyboardDismissMode={trackInteractive ? 'interactive' : 'none'}
@@ -58,7 +58,7 @@ export default class KeyboardTrackingViewScreen extends PureComponent {
5858
))}
5959
</ScrollView>
6060
<KeyboardTrackingView style={styles.trackingToolbarContainer} trackInteractive={trackInteractive}>
61-
<View centerV style={styles.inputContainer}>
61+
<View centerV bg-white paddingH-s5 paddingV-s2>
6262
<TextField text70 placeholder={'Message'} floatingPlaceholder floatOnFocus/>
6363
</View>
6464
</KeyboardTrackingView>
@@ -68,10 +68,6 @@ export default class KeyboardTrackingViewScreen extends PureComponent {
6868
}
6969

7070
const styles = StyleSheet.create({
71-
container: {
72-
flex: 1,
73-
backgroundColor: Colors.dark80
74-
},
7571
scrollContainer: {
7672
paddingHorizontal: Spacings.s5
7773
},
@@ -85,10 +81,5 @@ const styles = StyleSheet.create({
8581
width: '100%',
8682
borderWidth: 1,
8783
borderColor: Colors.dark60
88-
},
89-
inputContainer: {
90-
paddingHorizontal: Spacings.s5,
91-
paddingVertical: Spacings.s2,
92-
backgroundColor: Colors.white
9384
}
9485
});
Lines changed: 75 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,57 @@
11
import React, {PureComponent} from 'react';
22
import {ScrollView, StyleSheet, TextInput} from 'react-native';
3-
import {
4-
KeyboardAccessoryView,
5-
KeyboardUtils,
6-
TouchableOpacity,
7-
Text,
8-
View,
9-
KeyboardTrackingView,
10-
TextField,
11-
Image,
12-
Colors,
13-
Spacings,
14-
Switch,
15-
Constants,
16-
Typography
17-
} from 'react-native-ui-lib';
18-
19-
// import './demoKeyboards';
3+
import {Keyboard, Text, View, Colors, Spacings, Constants, Typography, Button} from 'react-native-ui-lib';
4+
const KeyboardAccessoryView = Keyboard.KeyboardAccessoryView;
5+
const KeyboardUtils = Keyboard.KeyboardUtils;
6+
7+
import './demoKeyboards';
8+
const KeyboardRegistry = Keyboard.KeyboardRegistry;
209

2110
const TrackInteractive = true;
2211

2312
export default class KeyboardInputViewScreen extends PureComponent {
24-
constructor(props) {
25-
super(props);
26-
this.keyboardAccessoryViewContent = this.keyboardAccessoryViewContent.bind(this);
27-
this.onKeyboardItemSelected = this.onKeyboardItemSelected.bind(this);
28-
this.resetKeyboardView = this.resetKeyboardView.bind(this);
29-
this.onKeyboardResigned = this.onKeyboardResigned.bind(this);
30-
31-
this.state = {
32-
customKeyboard: {
33-
component: undefined,
34-
initialProps: undefined
35-
},
36-
receivedKeyboardData: undefined
37-
};
38-
}
13+
state = {
14+
customKeyboard: {
15+
component: undefined,
16+
initialProps: undefined
17+
},
18+
receivedKeyboardData: undefined
19+
};
3920

40-
onKeyboardItemSelected(keyboardId, params) {
21+
onKeyboardItemSelected = (keyboardId, params) => {
4122
const receivedKeyboardData = `onItemSelected from "${keyboardId}"\nreceived params: ${JSON.stringify(params)}`;
4223
this.setState({receivedKeyboardData});
43-
}
24+
};
4425

45-
onKeyboardResigned() {
26+
onKeyboardResigned = () => {
4627
this.resetKeyboardView();
47-
}
28+
};
4829

4930
getToolbarButtons() {
50-
return [
51-
{
52-
text: 'show1',
53-
testID: 'show1',
54-
onPress: () => this.showKeyboardView('KeyboardView', 'FIRST - 1 (passed prop)')
55-
},
56-
{
57-
text: 'show2',
58-
testID: 'show2',
59-
onPress: () => this.showKeyboardView('AnotherKeyboardView', 'SECOND - 2 (passed prop)')
60-
},
61-
{
62-
text: 'reset',
63-
testID: 'reset',
64-
onPress: () => this.resetKeyboardView()
65-
}
66-
];
31+
const keyboards = KeyboardRegistry.getAllKeyboards();
32+
const buttons = [];
33+
for (let index = 0; index < keyboards.length; ++index) {
34+
const string = `Show KB ${index + 1}`;
35+
const title = `Title ${index + 1} (passed prop)`;
36+
buttons.push({
37+
text: string,
38+
testID: string,
39+
onPress: () => this.showKeyboardView(keyboards[index].id, title)
40+
});
41+
}
42+
43+
buttons.push({
44+
text: 'reset',
45+
testID: 'reset',
46+
onPress: () => this.resetKeyboardView()
47+
});
48+
49+
return buttons;
6750
}
6851

69-
resetKeyboardView() {
52+
resetKeyboardView = () => {
7053
this.setState({customKeyboard: {}});
71-
}
54+
};
7255

7356
showKeyboardView(component, title) {
7457
this.setState({
@@ -79,10 +62,16 @@ export default class KeyboardInputViewScreen extends PureComponent {
7962
});
8063
}
8164

82-
keyboardAccessoryViewContent() {
65+
onHeightChanged = keyboardAccessoryViewHeight => {
66+
if (Constants.isIOS) {
67+
this.setState({keyboardAccessoryViewHeight});
68+
}
69+
};
70+
71+
keyboardAccessoryViewContent = () => {
8372
return (
8473
<View style={styles.keyboardContainer}>
85-
<View style={styles.inputContainer}>
74+
<View row padding-s5>
8675
<TextInput
8776
maxHeight={200}
8877
style={styles.textInput}
@@ -93,84 +82,82 @@ export default class KeyboardInputViewScreen extends PureComponent {
9382
underlineColorAndroid="transparent"
9483
onFocus={this.resetKeyboardView}
9584
/>
96-
<TouchableOpacity style={styles.closeButton} onPress={KeyboardUtils.dismiss}>
97-
<Text>Close</Text>
98-
</TouchableOpacity>
85+
<Button label="Close" link onPress={KeyboardUtils.dismiss} style={styles.button}/>
9986
</View>
10087

101-
<View style={styles.keyboardModesContainer}>
88+
<View row>
10289
{this.getToolbarButtons().map((button, index) => (
103-
<TouchableOpacity onPress={button.onPress} style={styles.modeButton} key={index} testID={button.testID}>
104-
<Text>{button.text}</Text>
105-
</TouchableOpacity>
90+
<Button label={button.text} link onPress={button.onPress} key={index} style={styles.button}/>
10691
))}
10792
</View>
10893
</View>
10994
);
110-
}
95+
};
96+
97+
requestShowKeyboard = () => {
98+
KeyboardRegistry.requestShowKeyboard('KeyboardView1');
99+
};
100+
101+
onRequestShowKeyboard = componentID => {
102+
this.setState({
103+
customKeyboard: {
104+
component: componentID,
105+
initialProps: {title: 'Keyboard 1 opened by button'}
106+
}
107+
});
108+
};
111109

112110
render() {
111+
const {message} = this.props;
112+
const {receivedKeyboardData, customKeyboard} = this.state;
113+
113114
return (
114-
<View style={styles.container}>
115+
<View flex bg-dark80>
115116
<ScrollView
116117
contentContainerStyle={styles.scrollContainer}
117118
keyboardDismissMode={TrackInteractive ? 'interactive' : 'none'}
118119
>
119120
<Text text40 dark10 marginV-20 center>
120-
{this.props.message || 'Keyboards example'}
121+
{message || 'Keyboards example'}
121122
</Text>
122-
<Text testID={'demo-message'}>{this.state.receivedKeyboardData}</Text>
123+
<Text testID={'demo-message'}>{receivedKeyboardData}</Text>
124+
<Button label={'Open keyboard #1'} link onPress={this.requestShowKeyboard} style={styles.button}/>
123125
</ScrollView>
124126

125127
<KeyboardAccessoryView
126128
renderContent={this.keyboardAccessoryViewContent}
127-
onHeightChanged={Constants.isIOS ? height => this.setState({keyboardAccessoryViewHeight: height}) : undefined}
129+
onHeightChanged={this.onHeightChanged}
128130
trackInteractive={TrackInteractive}
129131
kbInputRef={this.textInputRef}
130-
kbComponent={this.state.customKeyboard.component}
131-
kbInitialProps={this.state.customKeyboard.initialProps}
132+
kbComponent={customKeyboard.component}
133+
kbInitialProps={customKeyboard.initialProps}
132134
onItemSelected={this.onKeyboardItemSelected}
133135
onKeyboardResigned={this.onKeyboardResigned}
134136
revealKeyboardInteractive
137+
onRequestShowKeyboard={this.onRequestShowKeyboard}
135138
/>
136139
</View>
137140
);
138141
}
139142
}
140143

141144
const styles = StyleSheet.create({
142-
container: {
143-
flex: 1,
144-
backgroundColor: Colors.dark80
145-
},
146145
scrollContainer: {
147146
paddingHorizontal: Spacings.s5,
148147
flex: 1,
149148
justifyContent: 'center'
150149
},
151-
inputContainer: {
152-
flexDirection: 'row',
153-
alignItems: 'center',
154-
justifyContent: 'space-between',
155-
padding: Spacings.s5
156-
},
157150
textInput: {
158151
flex: 1,
159152
padding: Spacings.s2,
160153
...Typography.text70
161154
},
162-
closeButton: {
155+
button: {
163156
padding: Spacings.s2
164157
},
165158
keyboardContainer: {
166159
backgroundColor: Colors.white,
167160
borderWidth: 1,
168161
borderColor: Colors.dark60
169-
},
170-
keyboardModesContainer: {
171-
flexDirection: 'row'
172-
},
173-
modeButton: {
174-
padding: 5
175162
}
176163
});
Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,24 @@
11
import React, {Component} from 'react';
22
import PropTypes from 'prop-types';
3-
import {ScrollView, StyleSheet} from 'react-native';
4-
import {KeyboardRegistry, Text, TouchableOpacity} from 'react-native-ui-lib';
3+
import {View, Text, TouchableOpacity} from 'react-native-ui-lib';
54

65
export default class KeyboardView extends Component {
76
static propTypes = {
8-
title: PropTypes.string
7+
title: PropTypes.string,
8+
backgroundColor: PropTypes.string,
9+
onPress: PropTypes.func
910
};
1011

11-
onButtonPress() {
12-
KeyboardRegistry.onItemSelected('KeyboardView', {
13-
message: 'item selected from KeyboardView'
14-
});
15-
}
16-
1712
render() {
13+
const {title, backgroundColor, onPress} = this.props;
14+
1815
return (
19-
<ScrollView contentContainerStyle={[styles.keyboardContainer, {backgroundColor: 'purple'}]}>
20-
<Text style={{color: 'white'}}>HELOOOO!!!</Text>
21-
<Text style={{color: 'white'}}>{this.props.title}</Text>
22-
<TouchableOpacity
23-
testID={'click-me'}
24-
style={{padding: 20, marginTop: 30, backgroundColor: 'white'}}
25-
onPress={() => this.onButtonPress()}
26-
>
16+
<View flex center style={backgroundColor && {backgroundColor}}>
17+
<Text white>{title}</Text>
18+
<TouchableOpacity testID={'click-me'} padding-20 marginT-30 bg-white onPress={onPress}>
2719
<Text>Click Me!</Text>
2820
</TouchableOpacity>
29-
</ScrollView>
21+
</View>
3022
);
3123
}
3224
}
33-
34-
const styles = StyleSheet.create({
35-
keyboardContainer: {
36-
flex: 1,
37-
flexDirection: 'column',
38-
alignItems: 'center',
39-
justifyContent: 'center'
40-
}
41-
});
42-
43-
KeyboardRegistry.registerKeyboard('KeyboardView', () => KeyboardView); // TODO:

0 commit comments

Comments
 (0)