FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(ios): keep a keystroke from repeating what a textChange listener wrote by NathanWalker · Pull Request #11443 · NativeScript/NativeScript · GitHub

fix(ios): keep a keystroke from repeating what a textChange listener wrote - #11443

Open
NathanWalker wants to merge 1 commit into
mainfrom
fix/ios-textfield-listener-write
Open

NathanWalker wants to merge 1 commit into
mainfrom
fix/ios-textfield-listener-write

Conversation

Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

On iOS, TextField.textFieldShouldChangeCharactersInRangeReplacementString computes the typed result, raises textChange through textProperty.nativeValueChange, and then returns true. If a textChange listener sets a different text inside that event, Property.set pushes the new value to the native field right away, and UIKit then inserts the typed character on top of it. Typing b into a field an uppercasing handler had left at A shows ABb while the property reads AB; a handler that resets or caps the value sees the rejected character appear anyway.

This is not framework-specific. Any integration whose state update runs synchronously inside the native event (Angular change detection in the zone task, Solid and Svelte signals, Octane, plain textChange handlers) hits it; integrations that flush asynchronously (Vue's scheduler, React 18 batching) instead see the caret jump to the end after the transformed write lands. Surfaced through nativescript-community/octane#3 while verifying a controlled-input fix there. TextView is unaffected because its delegate reports after the edit is applied, and Android's TextWatcher does too.

What is the new behavior?

After raising textChange, the delegate returns false when the listener wrote a different text: the setter has already put that value in the native field, so nothing is applied on top. The valueFormatter branch already worked this way. A listener that leaves text alone, or writes the same value, changes nothing (the write is a no-op in core and the delegate still returns true).

Tests

apps/automated gains typeCharacterNatively, which delivers one keystroke the way UIKit does (ask the delegate, apply the replacement only if it agrees; append on Android), and testTextWrittenByTextChangeListenerIsNotRepeatedByTheKeystroke, an uppercasing textChange listener typed a then b, asserting AB on both the property and the native field. It is gated to iOS since only that delegate can apply a keystroke after the listener ran.

Full automated iOS suite on the simulator: 1817 OK, 0 failed with the fix; with only the core change stashed, the same suite fails exactly this test (Actual: <AAB>), so it guards the regression.

…wrote

`TextField`'s `shouldChangeCharactersInRange` delegate raised `textChange`
with the typed result and then returned `true`, so when a listener set a
different `text` during that event (a formatter, a cap, a reset) the setter
pushed that value to the native field and UIKit inserted the typed
character on top of it: typing `b` into a field an uppercasing handler had
left at `A` showed `ABb` for a property value of `AB`. Every framework
whose state applies synchronously inside the event hit it; `TextView` did
not, because its delegate reports after the edit is applied.

The delegate now returns `false` when the listener wrote a different
`text`, as the `valueFormatter` path already does, so the native field
keeps the listener's value.

nx-cloud Bot commented Sep 23, 2026 •
edited
Loading

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 9620822

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 3m 15s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded <1s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-09-23 00:45:13 UTC

pkg-pr-new Bot commented Sep 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nativescript/core@11443
npm i https://pkg.pr.new/@nativescript/vite@11443
npm i https://pkg.pr.new/@nativescript/webpack@11443

commit: 9620822

This branch has not been deployed

No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

1 participant


Back | FazBrowse Home | New Git URL