Repository navigation
feat!: add JS wrappers for the pay buttons - #53
Conversation
…oss re-renders ApplePayButton and GooglePayButton are now React components around the Nitro host components, which stay internal (closes #21): - onPress takes a plain function. The wrapper wraps it with callback() once per button and reads the latest handler at tap time, so a new handler on each render does not update the native view. - disabled ignores taps. The button looks the same, as Apple's and Google's guidelines ask. - On the other platform a button renders nothing, with a warning in development. iOS rebuilds PKPaymentButton only when buttonType or buttonStyle changes. Android converts GooglePayButton's radius from dp to the px that ButtonOptions.setCornerRadius takes. BREAKING CHANGE: onPress is typed () => void, so onPress={callback(fn)} no longer type-checks. It still works at runtime, with a warning in development. hybridRef is no longer a button prop.
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
JavaScript wrappers and press handling package/src/components/*, package/src/index.ts, package/src/hooks/usePaymentCheckout.ts, example/app/(tabs)/index.tsx, package/jest.config.js |
Adds exported Apple Pay and Google Pay wrappers with direct onPress, optional disabled, platform guards, and development warnings for wrapped callbacks. Tests cover wrapper behavior, and examples pass handlers directly. |
Native lifecycle and sizing package/ios/HybridApplePayButton.swift, package/ios/Tests/HybridApplePayButtonTests.swift, package/android/src/main/java/.../GooglePayButtonFactory.kt, package/android/src/test/.../GooglePayButtonFactoryTest.kt, package/src/specs/GooglePayButton.nitro.ts |
iOS reuses the native button when type and style are unchanged. Android converts radius from dp to pixels. Tests check button reuse, latest handler invocation, and radius conversion. |
API guidance and usage migration README.md, docs/docs/*, CHANGELOG.md, AGENTS.md |
Updates examples and guidance to use direct handlers. Documents disabled behavior, unsupported-platform rendering, exported types, development warnings, and dp radius sizing. |
Priority:
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Feature · Severity of issue fixed: Medium
Sequence Diagram(s)
sequenceDiagram
participant Caller
participant ApplePayButton
participant usePayButtonPress
participant NativeHostComponent
Caller->>ApplePayButton: pass onPress and disabled
ApplePayButton->>usePayButtonPress: provide handler and disabled state
usePayButtonPress->>NativeHostComponent: provide stable native callback
NativeHostComponent->>usePayButtonPress: invoke callback on tap
usePayButtonPress->>Caller: invoke latest handler unless disabled
Possibly related issues
Possibly related PRs
- gmi-software/react-native-pay#35 — This PR replaces the callback-wrapping pay-button contract with direct handlers.
- gmi-software/react-native-pay#51 — The Google Pay wrapper uses native props that PR
#51added. - gmi-software/react-native-pay#44 — Both PRs keep callback behavior current across updates, at adjacent layers.
Merge Risk: 
Minimal · up to 3accd
-
The pay-button changes are ready to merge after normal checks.
Pre-merge checks: 
5 · 
1
-
Failed checks: 1 warning Passed checks: 5 passed-
Full details: Title check
-
Explanation
Title fails the stated requirement of being under 50 characters with a type prefix. It does have the "feat!:" type prefix and 42 characters, so it complies on length and type. It describes the main change: JS wrappers for the pay buttons, which matches the changeset. Cruelly speaking: the title is short, accurate, and at least it is not lying.
Full details: Description check
-
Explanation
The description is detailed and directly describes the changeset: the React wrappers, the disabled prop, the iOS PKPaymentButton rebuild logic, the Android dp-to-px radius conversion, exported types, docs updates, and test results. It is far from off-topic. Brutally put: it is thorough, which is more than most descriptions manage.
Full details: Linked Issues check
-
Explanation
Directly linked issue
#21has three acceptance criteria. All three are met by the PR summary and the tests it reports.[
#21] PlainonPresswithoutcallback():ApplePayButtonandGooglePayButtonare exported React wrappers.usePayButtonPresswraps the handler withcallback()once and reads the latest handler at tap time.index.tsre-exports the wrappers. README, docs and examples no longer usecallback(). Render tests inPayButtons.test.tsxcover handler updates.[
#21] Changing onlyonPressdoes not create a newPKPaymentButton:HybridApplePayButtonstores the type and style used to build the button.afterUpdate()rebuilds only when one of them changes.HybridApplePayButtonTests(3 tests) check reuse ononPress-only change, rebuild on type or style change, and that a tap calls the latestonPress.[
#21] Other platform renders a no-op: each wrapper returnsnullwith a__DEV__warning on the unsupported platform. Tests cover this.[
#21]disabledprop: taps are ignored inusePayButtonPress. The PR does not dim the button. The issue's suggested fix says to dim "within platform guidelines". The PR cites Apple HIG and Google brand guidelines against dimming. No acceptance criterion requires dimming, so this deviation is accepted.[
#21] Androidradius:cornerRadiusPxconverts dp to px.GooglePayButtonFactoryTestcovers scaling, zero, and rounding.Optional items (
cornerRadius, Apple Payautomaticstyle) are deferred. They are not required.Gap: the issue's Testing section suggests a benchmark that counts native button creations. The PR adds a unit test for the same behavior instead. This does not block the acceptance criteria.
Not run: the iOS and Android example app runs. These are manual checks, not coding requirements.
Full details: Out of Scope Changes check
-
Explanation
Every changed area maps to issue
#21or supports its API.- Wrapper components,
usePayButtonPress, and the re-exports inindex.ts: implement the wrapper requirement. - Removal of
hybridRefas a button prop: follows from keeping the Nitro host components internal. The buttons have no methods to reach. - Exported type and props declarations: needed for the new public wrapper API.
- Legacy
callback()handling with a development warning: supports migration from the old API. - iOS
HybridApplePayButtonchange andHybridApplePayButtonTests: implement the rebuild requirement and test it. - Android
cornerRadiusPxand its unit test: implement the radius requirement (issue item 4). jest.config.js*.test.tsxmatch: needed to run the new render tests.- README,
docs/,AGENTS.md,CHANGELOG.md, example app: document and demonstrate the new API.
No unrelated product behavior is shown in the summary. Scope is judged from the summary. The per-file diff was not read in this pass.
- Wrapper components,
Full details: Security Check
-
Explanation
No medium, high, or critical vulnerability was introduced. The changed code only adds React wrappers, fixed platform warnings, callback dispatch, iOS button reuse, and Android radius conversion. It does not add network or filesystem access, dynamic code execution, deserialization, authorization logic, secret logging, URL handling, or query construction. The callback path invokes the supplied handler on a user tap, and the radius value only configures button appearance. No prior unresolved security findings were supplied.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 18 functions across 13 files. (11 skipped: 11 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Warning
Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption.
Comment @coderabbitai help to get the list of available commands.
# Conflicts: # CHANGELOG.md
|
@coderabbitai review |
|
|
@coderabbitai full review |
|
|
@coderabbitai full review |
✅ Action performed
|
Closes #21.
Summary
ApplePayButtonandGooglePayButtonare now React components around the Nitro host components, which stay internal.onPresstakes a plain function: the wrapper wraps it withcallback()once per button and reads the latest handler at tap time, so a new handler on each render no longer updates the native view.disabledprop ignores taps. It does not dim the button: Apple's HIG says "Don't hide an Apple Pay button or make it appear unavailable", and Google's brand guidelines forbid changing the button's color. Apps can still setopacitythemselves.null, with a__DEV__warning, instead of failing to find the native view.HybridApplePayButtonrebuildsPKPaymentButtononly whenbuttonTypeorbuttonStylechanges (it rebuilt on every prop update).radiusis converted from dp to px.ButtonOptions.setCornerRadiustakes px, so corners were about a third of the requested size on a typical phone.Also exported:
ApplePayButtonType,ApplePayButtonStyle,GooglePayButtonType,GooglePayButtonTheme,ApplePayButtonProps,GooglePayButtonProps. README,docs/, the example app,AGENTS.mdandCHANGELOG.mdno longer usecallback().docs/docs/api/components.mddocumentsdisabledand the platform behavior.Test plan
cd package && bun run typecheck: passescd package && bun run lint: passescd package && bun run test:ci: 133 passed. 9 are new render tests insrc/components/__tests__/PayButtons.test.tsx, with the host component mocked. Removing thedisabledcheck makes 2 of them fail../gradlew :gmisoftware_react-native-pay:testDebugUnitTestinexample/android: passes, including the newGooglePayButtonFactoryTestxcodebuild test ... -scheme NitroPay-Unit-Testsinexample/ios: the full run passed 50 of 51 tests. The failure was the new tap test: the test bundle has no app host, sosendActions(for:)does nothing. After the fix, the newHybridApplePayButtonTests(3 tests) pass. They check that the button is kept when onlyonPresschanges, rebuilt when the type or style changes, and that a tap calls the latestonPress.cd package && bun run check:docs: 64 snippets type-checkcd package && bun run check:pack: contents OKbun run docs:build: passes, no broken linkscd example && bunx expo run:ios(not run: the wrapper passes the same{ f }callback object to the same host component as before, and the tap path is covered by the tests above)cd example && bunx expo run:android(not run, so the larger corner radius has not been checked on a device)Risk
onPressis typed() => void, soonPress={callback(fn)}no longer type-checks. It still works at runtime, with a warning in development. The migration is to dropcallback(.hybridRefis no longer a button prop. The buttons have no methods, so it gave access to nothing.radius. Apps that enlargedradiusto compensate should set it back (noted in the CHANGELOG).Notes
cornerRadiusand theautomaticstyle forApplePayButton) is left for a follow-up.disabledis not exposed to VoiceOver or TalkBack, because the wrapper does not change the native control.jest.config.jsnow also matches*.test.tsx.Need help on this PR? Tag
@codesmith-botwith what you need.