-
Notifications
You must be signed in to change notification settings - Fork 1
/
AppDemo.tsx
103 lines (94 loc) · 2.34 KB
/
AppDemo.tsx
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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* Generated with the TypeScript template
* https://github.com/emin93/react-native-template-typescript
*
*/
import React from "react";
import { StyleSheet, Text, TextInput, View } from "react-native";
import createIOSKeyboardEvents from "./src/IOSKeyboardEvents";
import { KeyboardState } from "./src/keyboardTransitions";
interface IState {
currentKeyboardState: KeyboardState;
}
export default class AppDemo extends React.Component<{}, IState> {
private IOSKbEvents = createIOSKeyboardEvents({
keyboardEventDebounceTime: 100,
});
constructor(props: {}) {
super(props);
this.state = {
currentKeyboardState: this.IOSKbEvents.getKeyboardState(),
};
}
public render() {
return (
<View style={styles.container}>
<View>{createCurrentStateLabel(this.state.currentKeyboardState)}</View>
<View>
<TextInput
placeholder="Type here!"
style={styles.textInput}
autoFocus
/>
</View>
<View style={styles.bottomContainer}>
{createCurrentStateLabel(this.state.currentKeyboardState)}
</View>
</View>
);
}
public componentDidMount() {
this.IOSKbEvents.addListener(
"keyboardListener",
(newKeyboardState, previousState) => {
console.log(`state change: ${previousState} -> ${newKeyboardState}`);
this.setState({
currentKeyboardState: newKeyboardState,
});
},
);
}
public componentWillUnmount() {
this.IOSKbEvents.close();
}
}
const createCurrentStateLabel = (
currentKeyboardState: KeyboardState,
): React.ReactNode => {
return (
<Text style={styles.title}>
<Text>Current State: </Text>
<Text style={{ fontWeight: "bold" }}>{currentKeyboardState}</Text>
</Text>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "flex-start",
alignItems: "center",
backgroundColor: "white",
paddingTop: 50,
},
title: {
fontSize: 20,
},
textInput: {
borderWidth: 1,
width: 200,
borderRadius: 5,
marginRight: 5,
padding: 10,
},
bottomContainer: {
flex: 1,
justifyContent: "flex-start",
alignItems: "center",
backgroundColor: "white",
position: "absolute",
top: "90%",
},
});