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

useAnimatedKeyboard() return wrong height if keyboard already opened #7077

Open
wvq opened this issue Feb 24, 2025 · 1 comment
Open

useAnimatedKeyboard() return wrong height if keyboard already opened #7077

wvq opened this issue Feb 24, 2025 · 1 comment
Labels
Missing repro This issue need minimum repro scenario Platform: iOS This issue is specific to iOS

Comments

@wvq
Copy link

wvq commented Feb 24, 2025

Description

If keyboard already opened in current screen, when navigate to next screen and focus TextInput, const { height } = useAnimatedKeyboard() is 0, It should be Keyboard.metrics().height, the state is also wrong , should be KeyboardState.OPEN

Steps to reproduce

import { useEffect, useRef } from 'react'
import { SafeAreaView, TextInput } from 'react-native'
import Animated, { useAnimatedKeyboard, useAnimatedStyle } from 'react-native-reanimated'

// open keyboard in this screen
export function MainScreen() {
  return (
    <SafeAreaView>
      <TextInput />
    </SafeAreaView>
  )
}

export function NextScreen() {
  const { height } = useAnimatedKeyboard()

  const ref = useRef<TextInput>(null)

  const isInit = useRef(false)

  const animatedStyle = useAnimatedStyle(() => {
    return {
      transform: [{ translateY: -height.value }],
    }
  })

  useEffect(() => {
    if (isInit.current === false && ref.current !== null) {
      ref.current.focus()
    }
  }, [ref])

  return (
    <SafeAreaView>
      <Animated.View style={[{ alignSelf: 'flex-end' }, animatedStyle]}>
        <TextInput ref={ref} />
      </Animated.View>
    </SafeAreaView>
  )
}

Snack or a link to a repository

sorry, snack.expo.io not work for me

Reanimated version

3.16.7

React Native version

0.77.1

Platforms

iOS

JavaScript runtime

None

Workflow

None

Architecture

None

Build type

None

Device

None

Device model

No response

Acknowledgements

Yes

Copy link

Hey! 👋

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?

@github-actions github-actions bot added Missing repro This issue need minimum repro scenario Platform: iOS This issue is specific to iOS labels Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Missing repro This issue need minimum repro scenario Platform: iOS This issue is specific to iOS
Projects
None yet
Development

No branches or pull requests

1 participant