Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: focused input #257

Merged
merged 8 commits into from
Oct 23, 2023
Merged

feat: focused input #257

merged 8 commits into from
Oct 23, 2023

Conversation

kirillzyusko
Copy link
Owner

@kirillzyusko kirillzyusko commented Oct 19, 2023

📜 Description

Added new useReanimatedFocusedInput hook that returns an information about TextInput that currently is in focus.

💡 Motivation and Context

Before we could use a target property to measure TextInput. However such approach had several disadvantages:

  • on Fabric you need to have an access to ShadowNode and it adds more complexity to the code (and you need to use findNodeHandle which is deprecated in StrictMode);
  • if view layout was changed - you are still not aware about it, because useKeyboardHandler is not reporting such cases (and obviously it shouldn't);
  • it seems like measure on Fabric works differently and you need to take into consideration other UI elements (header height, etc.)

With the introduction of this hook all these disadvantages are gone 😎

In this hook can be enhanced to cover more cases (for example add method update which can synchronously update layout before reading it, or update layout when certain lifecycle events occurs (for example screen rotation)).

Closes #249 #222

📢 Changelog

Docs

  • added a new group Input in API section;
  • added a new page for new useReanimatedFocusedInput hook;
  • added new key feature in README;
  • added new keywords to package.json.

JS

  • update KeyboardAwareScrollView UI (don't generate colors randomly anymore);
  • detect growth of TextInputs;
  • unified codebase across RN architectures (fabric, paper);
  • added new unit tests for new hook;

iOS

  • added KVO to focused input;

Android

  • all listeners (callbacks, observers) now live in listeners package;
  • removed zombie-view (on Fabric)
  • listener clean up after setEnabled call

🤔 How Has This Been Tested?

Tested manually on (both paper and fabric):

  • iPhone 6s (iOS 15.6);
  • iPhone 11 (iOS 17.0);
  • Pixel 7 Pro (Android 14);
  • Xiaomi Redmi Note 5 Pro (Android 9);
  • iPhone 15 (iOS 17.0, simulator);
  • Pixel 3a (Android 13, emulator).

📸 Screenshots (if appropriate):

Screen.Recording.2023-10-20.at.00.08.29.mov

📝 Checklist

  • CI successfully passed

@kirillzyusko kirillzyusko added enhancement New feature or request focused input 📝 Anything about focused input functionality labels Oct 19, 2023
@kirillzyusko kirillzyusko self-assigned this Oct 19, 2023
@kirillzyusko kirillzyusko added the documentation Improvements or additions to documentation label Oct 19, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Oct 19, 2023

📊 Package size report

Current size Target Size Difference
77912 bytes 73638 bytes 4274 bytes 📈

@github-actions
Copy link
Contributor

PR Preview Action v1.4.4
🚀 Deployed preview to https://kirillzyusko.github.io/react-native-keyboard-controller/pr-preview/pr-257/
on branch gh-pages at 2023-10-19 20:51 UTC

@kirillzyusko kirillzyusko marked this pull request as ready for review October 22, 2023 14:14
@kirillzyusko kirillzyusko merged commit 4e65942 into main Oct 23, 2023
@kirillzyusko kirillzyusko deleted the feat/focused-input branch October 23, 2023 07:59
kirillzyusko added a commit that referenced this pull request Jan 12, 2024
## 📜 Description

Removed view wrapper. Attached that view as last child + kept padding
for this view.

## 💡 Motivation and Context

The approach with additional view was added in
#257

I don't remember exact reason, but for me it seems like it was added,
because TExtInputs were not able to grow. However such approach is
causing additional issues:

- breaks styling in some cases
- stickyHeaderIndices={[0]} produces a crash (because RN will try to
attach `Animated`-based style to REA view)

So in this PR I'm removing this view wrapper and apply additional
padding in mostly the same way as it was before
#257
(additional child-view in the end of ScrollView, but instead of `height`
I'm animating `paddingBottom`).

I've tested and it still works (i. e. inputs are growing). E2E tests
also passing (so there seems to be 1px difference, which can be
neglected, but i had to update assets to assure E2E tests consistency).

> [!IMPORTANT]
> This fix will introduce
software-mansion/react-native-reanimated#5567.
I've added that issue as "known issue" in docs page.
I think it's better to have properly working paper architecture and
Fabric can be fixed later (because it's still in early adoption and is
not widely used).

Closes
#325

## 📢 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 -->

### E2E

- added `detox-clean` command (useful when you updated XCode version and
haven't run detox tests yet)

### JS

- removed wrapper and moved view as last child

## 🤔 How Has This Been Tested?

Tested on:
- e2e (Android, iOS - paper)
- Pixel 7 Pro (Android 14, paper)

## 📸 Screenshots (if appropriate):

There is no visual difference 🙂 

## 📝 Checklist

- [x] CI successfully passed
kirillzyusko added a commit that referenced this pull request Jan 13, 2024
…ScrollView` (#332)

## 📜 Description

Synchronized bottom padding with keyboard frame in
`KeyboardAwareScrollView`.

## 💡 Motivation and Context

Original regression was introduced in
#257
([these](https://github.com/kirillzyusko/react-native-keyboard-controller/pull/257/files#diff-b4493213c8dc470b5ba251af896d133130cc8996cee1118525e4eba1f3aa993bL87-L88)
code lines). I decided not animated bottom padding to potentially fix
the issue described in
#255 (comment)

However such approach is causing unsynchronized animations in certain
conditions and I'm not sure, that it actually fixes the problem
described in comment above.

So in this PR I'm reworking it again and bringing back animated
transitions 👀

Closes
#329

## 📢 Changelog

### JS

- added `currentKeyboardFrameHeight` variable;
- update `currentKeyboardFrameHeight` variable in `onMove` handler;
- use `currentKeyboardFrameHeight` for bottom padding in KASV.

## 🤔 How Has This Been Tested?

Tested manually on iPhone 15 Pro + e2e tests.

## 📸 Screenshots (if appropriate):

|Before|After|
|-------|-----|
|<video
src="https://github.com/kirillzyusko/react-native-keyboard-controller/assets/22820318/a7e5e3d3-8ef0-4b69-8c21-2414b1899e91">|<video
src="https://github.com/kirillzyusko/react-native-keyboard-controller/assets/22820318/bdd34dee-25bd-4491-8612-6048c88760bb">|

## 📝 Checklist

- [x] CI successfully passed
- [x] I added new mocks and corresponding unit-tests if library API was
changed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request focused input 📝 Anything about focused input functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KeyboardAwareScrollView example causing some error related to view-flattened thrown by Reanimated
1 participant