Skip to content

Conversation

@SjaakSchilperoort
Copy link
Member

Fix for the autoFocus property passed to TextInput by InputField not working reliably anymore on React Native 0.83

autoCapitalize="none"
onFocus={() => setIsFocused(true)}
onBlur={() => setIsFocused(false)}
onLayout={() => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blijkbaar (maar kan er geen reports van vinden) kan autoFocus worden uitgevoerd als de component is gemount, maar nog niet attached. In Fabric is de timing van deze events anders. De fix hier is om een expliciete focus te doen op een moment dat we weten dat het ook werkt. Gebeurt eenmalig na mount.

Dit fixt het gedrag van Observation op React Native 0.83.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ik heb hier eerder ook wel een last van gehad, dit lijkt me een goede oplossing. Waarom heb je requestAnimationFrame nodig? (copilot zette hem ook voor mij er neer toen ik iets anders probeerde 😄 )

Het werkt nog niet helemaal lekker overigens. Het lijkt erop dat ie soort van onthoudt wat je hebt gedaan.
Als ik vanuit het AddObservationScreen naar het SelectSpeciesScreen ga (en heen en weer), werkt 't goed, maar als ik 1x het keyboard sluit komt het scherm niet meer terug als ik heen en weer ga.

Screen.Recording.2025-12-18.at.10.21.46.mov

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ref={inputRef} mist nog, dat verklaart mijn bug ook wel een beetje.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ref={inputRef} mist nog, dat verklaart mijn bug ook wel een beetje.

Beetje suf, toegevoegd.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waarom heb je requestAnimationFrame nodig?

Het onLayout event zelf kan nog steeds op een verkeerd moment komen. De callback in requestAnimationFrame wordt aangeroepen na afloop van de huidige layout en render cycle, en dat is laat genoeg. Alternatief was om dit separaat te doen, via InteractionManager.runAfterInteractions, maar ik weet niet of dat betrouwbaar is, en die is bovendien deprecated.

Copy link
Collaborator

@jonathan-waarneming-nl jonathan-waarneming-nl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 Wat een gedoe...

autoCapitalize="none"
onBlur={[Function]}
onFocus={[Function]}
onLayout={[Function]}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je zou er nog voor kunnen kiezen om geen functie mee te geven als er geen autoFocus moet gebeuren.

@SjaakSchilperoort SjaakSchilperoort merged commit 4eea3ba into develop Dec 18, 2025
2 checks passed
@SjaakSchilperoort SjaakSchilperoort deleted the bugfix/fix-auto-focus-on-input-field branch December 18, 2025 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants