question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to respond to events like TextInput focus/blur and Keyboard show/hide

See original GitHub issue

Hello. I love the concept of reanimated, and understand how to implement some basic animations using it. However, I am stuck on how to respond to events that require communication over the bridge. I have 2 primary use cases I’m currently trying to solve for:

  1. Run an animation when a TextInput is focused, run the animation in reverse when the TextInput is blurred.
  2. Run an animation when the Keyboard is shown, run the animation in reverse when the Keyboard is hidden.

I’ve read the documentation a few times and have checked out most of the examples, I couldn’t find a super clear solution for these requirements. I asked a more specific version of this question on Stack Overflow that includes a runnable example, but I know the implementation is wrong. I just am wondering what the recommended approach is for reacting to user-driven events other than touch/gestures (i.e. without using gesture handler lib and just hooking into events with the event function). Is this even a good use case for reanimated? Is it possible to achieve this and achieve 60 fps animations?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:20 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
osdnkcommented, Nov 18, 2019

I confirm that the solution of @ShaMan123 does not require a bridge. Under the hood, we’re not really evaluating this function of each frame, but we’re using proxy object and evaluate in only during mounting

0reactions
ShaMan123commented, Mar 13, 2020

Found It

The problem here is that the native event has a different name than the callback prop and reanimated doesn’t that. For example onBlur is called topBlur in native code, see source code android, ios. This is why the event doesn’t fire - reanimated is instructed to intercept events with name onBlur but there aren’t any. You can hack this with a workaround.

const rBlur= event<NativeSyntheticEvent<TextInputFocusEventData>>([
    {
      nativeEvent: { target: sub(target, target) }
    }
  ]);

<AnimatedTextInput
   onBlur={() => console.log('js received blur')}
   topBlur={rBlur}
/>

This way reanimated intercepts events that are named topBlur while react-native handles onBlur.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to detect keyboard show/ hide event in jquery for ...
I've tried focus, blur, browser resize event but my problem have not resolve 100%, so I am looking for only keyboard event, actually...
Read more >
How to make your React Native app respond gracefully ...
First off you want to set the backgroundColor of the ScrollView that way (if you were to re-enable scrolling) the backgroundColor is always...
Read more >
Hide a DIV when it loses focus/blur
Use (choose event based on your need): onmouseover OR onfocus : for showing the div onmouseout OR onblur : for hiding the div...
Read more >
Vue.js — Forms, components and considerations - webf
Native form input events. There are cases where you need to have a common event handler on <form> element for events like focus...
Read more >
force show/hide Soft Keyboard on EditText
Show software keyboard for numeric input EditText and hide on other input EditText. Applies To. Android 7, Android 8; CN80. Resolution.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found