Commit 60ec0ce
authored
feat: keyboard state selector (#998)
## 📜 Description
Added ability to pass selector to `useKeyboardState` hook to query only
necessary updates.
## 💡 Motivation and Context
The concept of selectors should be very familiar to many RN developers,
since it's used in `redux` and `zustand` packages. I was also thinking
about optimizing the amount of re-renders for this hook, but initially
I've been thinking of using proxy (similar to what `react-hook-form` is
doing). But such approach will introduce a lot of complexity, so I
decided to keep the codebase simple and efficient, so added a concept of
selectors.
Additionally I re-worked documnetation mainly focusing on:
- adding a sample how `useKeyboardAnimation` can be used as alternative;
- making warnings/tips shorter with corresponding references;
- adding the usage for selectors concept;
- use a real-world example with `useKeyboardState` (conditional
rendering instead of changing styles).
## 📢 Changelog
<!-- High level overview of important changes -->
<!-- For example: fixed status bar manipulation; added new types
declarations; -->
<!-- If your changes don't affect one of platform/language below - then
remove this platform/language -->
### JS
- allow to pass selectors to `useKeyboardState`;
### Docs
- make warning/tips shorter with corresponding links;
- added `useKeyboardState` vs `useKeyboardAnimation` code reference;
- mention how to use selectors;
- re-work example app to match real-world scenarios usage.
## 🤔 How Has This Been Tested?
Tested manually in example project.
## 📸 Screenshots (if appropriate):
|Dark theme|Light theme|
|------------|------------|
|||
## 📝 Checklist
- [x] CI successfully passed
- [x] I added new mocks and corresponding unit-tests if library API was
changed1 parent c299547 commit 60ec0ce
7 files changed
Lines changed: 116 additions & 33 deletions
File tree
- FabricExample/src/screens/Examples/LiquidKeyboard
- docs/docs/api/hooks/keyboard
- example/src/screens/Examples/LiquidKeyboard
- jest
- src/hooks/useKeyboardState
Lines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
19 | 23 | | |
20 | 24 | | |
21 | 25 | | |
22 | 26 | | |
23 | 27 | | |
| 28 | + | |
| 29 | + | |
24 | 30 | | |
25 | 31 | | |
| 32 | + | |
26 | 33 | | |
27 | 34 | | |
28 | 35 | | |
| |||
98 | 105 | | |
99 | 106 | | |
100 | 107 | | |
101 | | - | |
| 108 | + | |
102 | 109 | | |
103 | 110 | | |
104 | 111 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 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 | + | |
24 | 59 | | |
25 | 60 | | |
26 | 61 | | |
| |||
30 | 65 | | |
31 | 66 | | |
32 | 67 | | |
33 | | - | |
| 68 | + | |
34 | 69 | | |
35 | 70 | | |
36 | 71 | | |
| |||
48 | 83 | | |
49 | 84 | | |
50 | 85 | | |
51 | | - | |
| 86 | + | |
52 | 87 | | |
53 | 88 | | |
54 | 89 | | |
| |||
61 | 96 | | |
62 | 97 | | |
63 | 98 | | |
64 | | - | |
| 99 | + | |
65 | 100 | | |
66 | | - | |
67 | | - | |
68 | | - | |
| 101 | + | |
69 | 102 | | |
70 | | - | |
| 103 | + | |
| 104 | + | |
71 | 105 | | |
72 | | - | |
| 106 | + | |
73 | 107 | | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
84 | 122 | | |
85 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
86 | 143 | | |
87 | 144 | | |
88 | 145 | | |
89 | 146 | | |
90 | 147 | | |
91 | 148 | | |
92 | 149 | | |
93 | | - | |
| 150 | + | |
94 | 151 | | |
95 | | - | |
96 | | - | |
| 152 | + | |
| 153 | + | |
97 | 154 | | |
98 | 155 | | |
99 | | - | |
| 156 | + | |
100 | 157 | | |
101 | 158 | | |
102 | 159 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
19 | 23 | | |
20 | 24 | | |
21 | 25 | | |
22 | 26 | | |
23 | 27 | | |
| 28 | + | |
| 29 | + | |
24 | 30 | | |
25 | 31 | | |
| 32 | + | |
26 | 33 | | |
27 | 34 | | |
28 | 35 | | |
| |||
98 | 105 | | |
99 | 106 | | |
100 | 107 | | |
101 | | - | |
| 108 | + | |
102 | 109 | | |
103 | 110 | | |
104 | 111 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
15 | 19 | | |
16 | 20 | | |
17 | 21 | | |
18 | 22 | | |
19 | 23 | | |
| 24 | + | |
| 25 | + | |
20 | 26 | | |
21 | 27 | | |
22 | 28 | | |
| |||
32 | 38 | | |
33 | 39 | | |
34 | 40 | | |
35 | | - | |
36 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
37 | 45 | | |
38 | 46 | | |
39 | 47 | | |
40 | 48 | | |
41 | 49 | | |
42 | 50 | | |
43 | | - | |
| 51 | + | |
44 | 52 | | |
45 | 53 | | |
46 | 54 | | |
47 | 55 | | |
48 | 56 | | |
49 | 57 | | |
50 | | - | |
| 58 | + | |
51 | 59 | | |
52 | 60 | | |
53 | 61 | | |
54 | 62 | | |
55 | 63 | | |
56 | 64 | | |
57 | 65 | | |
58 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
0 commit comments