Skip to content

feat(vault): iOS host for the native card fields - #105

Open
Pradeep-kumar1202 wants to merge 5 commits into
feat/vault-native-androidfrom
feat/vault-native-ios
Open

Pradeep-kumar1202 wants to merge 5 commits into
feat/vault-native-androidfrom
feat/vault-native-ios

Conversation

@Pradeep-kumar1202

@Pradeep-kumar1202 Pradeep-kumar1202 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What

Changed on 2 Dec (381455e, with #104's 8f28874): native card fields only. The podspec no longer reads HYPERSWITCH_VAULT_NATIVE_FIELDS (a pod install that still sets it is told it is ignored). An app without the new architecture or below React Native 0.82 still builds with the stand-in, and pod install now warns that the card fields are not available in it; at run time the form reports unsupported_configuration and draws no field (the JavaScript is #104's). The device results under Testing were run before this change.

The iOS host for the vault's native card fields: the twin of the Android host in #104.

On iOS too, in a rebuilt app on the new architecture and a tested React Native version (0.82 to 0.88), each card field is a native view whose content runs in the vault's own JavaScript engine. No JavaScript changes here: the choosers, the native form and the native field from #104 are shared.

Pull request What it adds
#79 createDetachedCardForm: one card across separate React roots
#103 the JavaScript the vault's own engine runs, and the bundle toolchain
#104 the Android host, and the choice: native fields, or a clear error
#105 (this) the iOS host

Each is based on the one before it. Merge order: #79, #103, #104, #105, then the release pull request (README, release notes, version 2.0.0). Labelled DO NOT MERGE until the stack is ready.

How it works

Everything is Objective-C++ in ios/Source/; there is no Swift, so the pod needs no bridging.

File Job
HyperswitchVaultEngine A second RCTReactNativeFactory with its own delegate, the recipe hyperswitch-sdk-ios already uses for its own second engine. The delegate points it at hyperswitch-vault-fields.bundle inside the app (never a development server) and creates the hosted module itself, so the engine knows which instance carries its commands
HyperswitchVaultForm One form: a hidden root, and its commands. Every command is answered exactly once. A refusal after the command reached the bundle is marked delivered, which the merchant's side reports as unknown_outcome
HyperswitchVaultFormsModule The module the merchant's engine talks to
HyperswitchVaultHostedModule The module the bundle talks to
HyperswitchVaultFieldView The Fabric component view for one field. It stops its root in prepareForRecycle, because React Native reuses native views, and takes the blur / focus commands the merchant's React Native sends a focused text input

A second factory must not disturb the app. RCTReactNativeFactory assumes it is the app's only one: creating another raises if the app's own factory chose a different release level, and it takes over the process-wide third-party component provider and default colour space. So the vault's factory is created with the app's release level (the Info.plist key ReactNativeReleaseLevel, which Expo writes; Stable otherwise); the app's component provider and colour space are put back right after; and any Objective-C or C++ exception while creating it is caught, remembered and never retried. The form then fails before it mounts, and the fields render the plain way.

Differences from Android: there is no package list (the second host is given what the app links, through RCTAppDependencyProvider), and a root's tag exists as soon as the root is created. Owners are still matched by tag when an event arrives.

Builds without the engine (the podspec decides)

  • React Native 0.82 or newer on the new architecture: ios/Source and the bundle.
  • Below 0.82 on the new architecture: ios/Stub, the three classes doing nothing, with the module reporting bundled: false. They must exist: React Native's generated code names them for every new-architecture app, and a missing view class would crash the app at start.
  • Old architecture: ios/Empty, one empty file.

Files

  • New: ios/Source/ (12 files), ios/Stub/, ios/Empty/, react-native-hyperswitch-vault.podspec
  • Changed: package.json (codegenConfig.ios, files), src/specs/HyperswitchVaultFieldViewNativeComponent.ts (iOS no longer excluded)

Impact on existing merchants

Testing

The results below were run before 2 Dec, with the plain fallback and the opt-out switch. Since then the iOS change is the podspec and comments only; the podspec's syntax is checked, a pod install and device re-run are pending.

On a simulator. iPhone 17, iOS 26.5, the same app and the same flows as on Android. On this code, React Native 0.86, release builds:

Check Result
Three fields draw; two forms in one run tokenize; clear(), reset(), focus() pass
Text changes seen by the app's own JavaScript while typing 0; the same app with the plain fields: 46
Dark mode switched while a card is typed fields re-theme, card kept, tokenizes
Tap outside a field (with the simulator's on-screen keyboard) closes the keyboard
Built with HYPERSWITCH_VAULT_NATIVE_FIELDS=0 module reports bundled: false, plain fields, tokenizes
System log after the flows no Updating props for Surface, no sdkAuthorization (React Native's other log lines are there)

Every React Native version, on this code (the whole stack, both platforms, release builds, one row at a time): 35 of 35 rows pass.

React Native Android iOS
0.82, 0.83, 0.84, 0.85, 0.87, 0.88 native path: every check passes, 0 text changes; switch off: plain fields pass native path: every check passes, 0 text changes; switch off: plain fields pass
0.86 as above, plus a release build with R8 as above
0.80, 0.81 (new architecture) stub, plain fields, every check passes stub, plain fields, every check passes
0.79, old architecture stub, plain fields, every check passes empty file, plain fields, every check passes

Device logs after the flows: no Updating props for Surface line and no sdkAuthorization in any of the 80 Android captures, nor on iOS 0.86 and 0.88 (read right after their runs).

Not tested

  • A real iPhone; an Expo app, in particular one with a non-Stable release level (the code path was built, not run); React Native 0.76 to 0.78; use_frameworks!; the co-badged network picker; VoiceOver; rotation (the test app is portrait-only).

Tested since the review (26 and 30 Nov): in the test app (React Native 0.86.3), the form's first onChange before typing, accessibility labels, onReady, the cardholder name field, background and back (the card is kept and tokenizes), memory with one form open (+60 MB) and the time to draw the fields (+0.1 s). The merchant's demo app (S2SDemo, React Native 0.87.1, Debug, its own code unchanged): a saved card's CVC and a new card with the name on it, typed into the native fields (the view tree shows the CVC input inside the vault's own surface); both payments succeeded, and the system log held no card number, sdkAuthorization or client secret.

Not in this PR

  • The ready-made HyperswitchVaultForm on the native path.
  • README, release notes, the version bump.

Note for the reviewer

  • A Debug build of a test app can fail to link, and it is not this code. With React Native 0.86's prebuilt core, a Debug build of react-native-svg wants debug-only symbols the prebuilt core does not have. With the core built from source (RCT_USE_PREBUILT_RNCORE=0 pod install) it links. An app with that combination fails the same way without the vault.
  • No opt-out switch: HYPERSWITCH_VAULT_NATIVE_FIELDS was removed on 2 Dec, with the plain fallback.
  • Known, not fixed here:
    • On iOS the hosted module is also registered in the merchant's engine Fixed (014a46e): it is still in Codegen's app-wide list, but only the instance in the vault's own engine carries events; one in any other engine ignores them.
    • A fatal JavaScript error in the vault's engine ends the app in a Release build, as it does for the plain fields today; Android fails the forms instead.
    • Whether a tap can reach the vault's engine twice (the merchant's touch handler and the vault's own) has not been checked on a device.
    • Fixed (014a46e): the stub now has HyperswitchVaultFieldViewCls, which React Native 0.76's generated code references. Not yet built in a 0.76 app; the README's floor is 0.79.

@Pradeep-kumar1202
Pradeep-kumar1202 force-pushed the feat/vault-native-android branch from c2ffeff to 6e60c44 Compare November 25, 2026 12:05
@Pradeep-kumar1202
Pradeep-kumar1202 force-pushed the feat/vault-native-android branch from 6e60c44 to 223bca7 Compare November 30, 2026 04:55
@Pradeep-kumar1202
Pradeep-kumar1202 force-pushed the feat/vault-native-ios branch 2 times, most recently from 107a0dc to 381455e Compare December 2, 2026 04:58
Pradeep-kumar1202 added a commit that referenced this pull request Dec 2, 2026
… command can see the old ones

The form room applied a settings update from native in a passive effect, which runs a moment after
the render commits. A tokenize command handled in that moment saw the previous settings, and so
the previous session, as current. The update now runs in a layout effect, while the render commits;
from then on form.tokenize() (#79's createDetachedCardForm) waits for the Host to draw the new
settings, so the command uses the new session.

Not covered here: a command that native code sends before the props update has reached the engine
at all. Keeping that order is the native hosts' part (#104, #105).
Pradeep-kumar1202 added a commit that referenced this pull request Dec 3, 2026
… command can see the old ones

The form room applied a settings update from native in a passive effect, which runs a moment after
the render commits. A tokenize command handled in that moment saw the previous settings, and so
the previous session, as current. The update now runs in a layout effect, while the render commits;
from then on form.tokenize() (#79's createDetachedCardForm) waits for the Host to draw the new
settings, so the command uses the new session.

Not covered here: a command that native code sends before the props update has reached the engine
at all. Keeping that order is the native hosts' part (#104, #105).
@Pradeep-kumar1202
Pradeep-kumar1202 force-pushed the feat/vault-native-android branch from 8f28874 to 5bc745b Compare December 3, 2026 05:51
Pradeep-kumar1202 added a commit that referenced this pull request Dec 3, 2026
… command can see the old ones

The form room applied a settings update from native in a passive effect, which runs a moment after
the render commits. A tokenize command handled in that moment saw the previous settings, and so
the previous session, as current. The update now runs in a layout effect, while the render commits;
from then on form.tokenize() (#79's createDetachedCardForm) waits for the Host to draw the new
settings, so the command uses the new session.

Not covered here: a command that native code sends before the props update has reached the engine
at all. Keeping that order is the native hosts' part (#104, #105).
@Pradeep-kumar1202
Pradeep-kumar1202 force-pushed the feat/vault-native-android branch from 5bc745b to 79c5305 Compare December 3, 2026 06:34
The iOS twin of the Android host: a second React Native factory that runs
the vault's own bundle, a form class, the two modules and the field view,
in Objective-C++. The field view takes the blur and focus commands the
merchant's React Native sends a focused text input.

The podspec compiles a stand-in with no engine and no bundle when React
Native is below 0.82 or pod install runs with
HYPERSWITCH_VAULT_NATIVE_FIELDS=0, and nothing on the old architecture.
…the app, and a delivered tokenize is an unknown outcome

RCTReactNativeFactory assumes it is the app's only factory. Creating the
vault's raised an uncaught NSException when the app's own factory used a
non-Stable release level (Expo exposes it as reactNativeReleaseLevel), and it
replaced the app's third-party Fabric component provider and default colour
space for the whole process.

The vault's factory now uses the app's release level (Info.plist
ReactNativeReleaseLevel, as Expo writes it; Stable otherwise), puts the
component provider and the colour space back right after it is made, and
catches any Objective-C or C++ exception while it is made. A failure is
remembered and never retried; the form then fails before it mounts and the
fields fall back to plain JavaScript.

As on Android, a command that reached the bundle and then timed out, or
whose form closed or failed, is refused with "delivered": true, which the
merchant's side reports as unknown_outcome.
…nd the stub links on React Native 0.76

HyperswitchVaultHosted is registered for every engine in the app on iOS (codegen's
modulesProvider), so code in the merchant's engine could deliver a VAULT_FORM_ERROR to a form root
by its tag and push the form to the plain fields. The module now ignores emits from any instance
but the one the vault's engine attached.

The stub gains HyperswitchVaultFieldViewCls, which React Native 0.76's generated component provider
links against by name.
The iOS side of "native card fields only" (the JavaScript is in the commit before this stack's iOS
commits). The podspec no longer reads HYPERSWITCH_VAULT_NATIVE_FIELDS; a `pod install` that still
sets it is told it is ignored. An app without the new architecture or below React Native 0.82 still
builds with the stand-in, and `pod install` now warns that the card fields are not available in it,
and why: at run time the card form reports unsupported_configuration and draws no field.

The comments that said the forms fall back to plain fields now say what happens instead.
… settings on save

- An app on community JavaScriptCore (USE_THIRD_PARTY_JSC=1) gets the stand-in, and pod install
  says why: React Native's default delegate raises in createJSRuntimeFactory there, which would
  end the app at the first card field. As a second line of defence, creating the vault engine's
  root is caught (Objective-C and C++ exceptions), remembered and never retried, and the form
  reports that it did not start (unsupported_configuration).
- A save carries the settings it was accepted with. One queued while the form starts whose settings
  changed before it could run is refused, unsent (tokenization_failed, try again), as on Android.
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