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

fix: missing update in useWindowDimensions #701

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

kirillzyusko
Copy link
Owner

@kirillzyusko kirillzyusko commented Nov 18, 2024

📜 Description

Fixed broken layout of KeyboardAvoidingView when KeyboardAvoidingView mounted on app start.

💡 Motivation and Context

The problem was in fact, that event arrived after useState initalization, but before adding a new listener. So we had a missing event and as a result screenHeight was 0.

To fix this I applied a very similar logic to what useWindowDimensions hook does from react-native. When useEffect callback gets executed we update state with initialDimensions. The value of initialDimensions will be always actual, because it's located outside of the hook.

📢 Changelog

JS

  • force update state inside useEffect with initialDimensions;

🤔 How Has This Been Tested?

Tested manually on Medium_Phone_API_35.

📝 Checklist

  • CI successfully passed
  • I added new mocks and corresponding unit-tests if library API was changed

@kirillzyusko kirillzyusko added the 🐛 bug Something isn't working label Nov 18, 2024
@kirillzyusko kirillzyusko self-assigned this Nov 18, 2024
Copy link
Contributor

📊 Package size report

Current size Target Size Difference
161221 bytes 160875 bytes 346 bytes 📈

@kirillzyusko kirillzyusko marked this pull request as ready for review November 18, 2024 18:32
@kirillzyusko kirillzyusko merged commit 331472c into main Nov 18, 2024
12 checks passed
@kirillzyusko kirillzyusko deleted the fix/use-window-dimensions-missing-update branch November 18, 2024 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant