You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## 📜 Description
Revisited some concepts of
`useKeyboardState`/`KeyboardController.state()` etc.
## 💡 Motivation and Context
After preparing a new release I went through the changes and realized,
that it would be better to take a step back and keep `isVisible`/`state`
decoupled but `useKeyboardState` should return data to all variables (i.
e. aggregate them).
## 📢 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 -->
### Docs
- mention animated hooks alternatives;
### JS
- don't include `isVisible` in `.state` method
- update types declaration to show that state doesn't return `null`
anymore;
## 🤔 How Has This Been Tested?
Tested via CI.
## 📝 Checklist
- [x] CI successfully passed
- [x] I added new mocks and corresponding unit-tests if library API was
changed
Copy file name to clipboardExpand all lines: docs/docs/api/hooks/keyboard/use-keyboard-state.mdx
+22-6Lines changed: 22 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,21 +5,21 @@ sidebar_position: 4
5
5
6
6
# useKeyboardState
7
7
8
-
`useKeyboardState` is a hook which gives an access to current keyboard state.
8
+
`useKeyboardState` is a hook which gives an access to current keyboard state. This hook combines data from `KeyboardController.state()` and `KeyboardController.isVisible()` methods and makes it reactive (i. e. triggers a re-render when keyboard state/visibility has changed).
9
9
10
10
:::warning
11
-
Use this hook only when you need to control `props` of views returned in JSX-markup. If you need to access the keyboard `state` in callbacks or event handlers then consider to use [KeyboardController.state()](../../keyboard-controller.md#state)method instead. This allows you to retrieve values as needed without triggering unnecessary re-renders.
11
+
Use this hook only when you need to control `props` of views returned in JSX-markup. If you need to access the keyboard `state` in callbacks or event handlers then consider to use [KeyboardController.state()](../../keyboard-controller.md#state)or [KeyboardController.isVisible()](../../keyboard-controller.md#isvisible) methods instead. This allows you to retrieve values as needed without triggering unnecessary re-renders.
Also make sure that if you need to change style based on keyboard presence then you are using corresponding [animated](./use-keyboard-animation) hooks to offload animation to a native thread and free up resources for JS thread.
56
+
:::
57
+
54
58
## Data structure
55
59
56
-
`useKeyboardState` returns a [`KeyboardState`](../../keyboard-controller.md#state) object.
60
+
The `KeyboardState` is represented by following structure:
61
+
62
+
```ts
63
+
typeKeyboardState= {
64
+
isVisible:boolean;
65
+
height:number;
66
+
duration:number; // duration of the animation
67
+
timestamp:number; // timestamp of the event from native thread
68
+
target:number; // tag of the focused `TextInput`
69
+
type:string; // `keyboardType` property from focused `TextInput`
70
+
appearance:string; // `keyboardAppearance` property from focused `TextInput`
0 commit comments