Skip to content

feat!: add JS wrappers for the pay buttons - #53

Merged
jkasprzyk17 merged 2 commits into
mainfrom
feat/pay-button-wrappers
Oct 27, 2026
Merged

jkasprzyk17 merged 2 commits into
mainfrom
feat/pay-button-wrappers

Conversation

@jkasprzyk17

@jkasprzyk17 jkasprzyk17 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Closes #21.

Summary

  • ApplePayButton and GooglePayButton are now React components around the Nitro host components, which stay internal. 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 no longer updates the native view.
  • New disabled prop 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 set opacity themselves.
  • On the other platform a button renders null, with a __DEV__ warning, instead of failing to find the native view.
  • iOS: HybridApplePayButton rebuilds PKPaymentButton only when buttonType or buttonStyle changes (it rebuilt on every prop update).
  • Android: radius is converted from dp to px. ButtonOptions.setCornerRadius takes 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.md and CHANGELOG.md no longer use callback(). docs/docs/api/components.md documents disabled and the platform behavior.

Test plan

  • cd package && bun run typecheck: passes
  • cd package && bun run lint: passes
  • cd package && bun run test:ci: 133 passed. 9 are new render tests in src/components/__tests__/PayButtons.test.tsx, with the host component mocked. Removing the disabled check makes 2 of them fail.
  • ./gradlew :gmisoftware_react-native-pay:testDebugUnitTest in example/android: passes, including the new GooglePayButtonFactoryTest
  • xcodebuild test ... -scheme NitroPay-Unit-Tests in example/ios: the full run passed 50 of 51 tests. The failure was the new tap test: the test bundle has no app host, so sendActions(for:) does nothing. After the fix, the new HybridApplePayButtonTests (3 tests) pass. They check that the button is kept when only onPress changes, rebuilt when the type or style changes, and that a tap calls the latest onPress.
  • cd package && bun run check:docs: 64 snippets type-check
  • cd package && bun run check:pack: contents OK
  • bun run docs:build: passes, no broken links
  • cd 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

  • Breaking type change: onPress is typed () => void, so onPress={callback(fn)} no longer type-checks. It still works at runtime, with a warning in development. The migration is to drop callback(.
  • hybridRef is no longer a button prop. The buttons have no methods, so it gave access to nothing.
  • Android corners get larger for apps that pass radius. Apps that enlarged radius to compensate should set it back (noted in the CHANGELOG).

Notes

  • Item 3 of the issue (cornerRadius and the automatic style for ApplePayButton) is left for a follow-up.
  • disabled is not exposed to VoiceOver or TalkBack, because the wrapper does not change the native control.
  • jest.config.js now also matches *.test.tsx.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

…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.
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: f374c4a2-f601-4bd2-bca1-98becbedfc36
Commits

Reviewing files that changed from the base of the PR and between 6ba1e57 and 3accd63.

Files selected for processing: 24
  • AGENTS.md
  • CHANGELOG.md
  • README.md
  • docs/docs/api/components.md
  • docs/docs/examples.md
  • docs/docs/guides/availability.md
  • docs/docs/guides/manual-flow.md
  • docs/docs/guides/server-processing.md
  • docs/docs/integrations/przelewy24.md
  • docs/docs/quick-start.md
  • docs/docs/troubleshooting.md
  • example/app/(tabs)/index.tsx
  • package/android/src/main/java/com/margelo/nitro/pay/GooglePayButtonFactory.kt
  • package/android/src/test/java/com/margelo/nitro/pay/GooglePayButtonFactoryTest.kt
  • package/ios/HybridApplePayButton.swift
  • package/ios/Tests/HybridApplePayButtonTests.swift
  • package/jest.config.js
  • package/src/components/ApplePayButton.tsx
  • package/src/components/GooglePayButton.tsx
  • package/src/components/__tests__/PayButtons.test.tsx
  • package/src/components/usePayButtonPress.ts
  • package/src/hooks/usePaymentCheckout.ts
  • package/src/index.ts
  • package/src/specs/GooglePayButton.nitro.ts

Included review availability: This review used your included allowance. 1 included review remains after this review. Your included PR review attempts over the past 7 days set your current allowance at 3 reviews per hour.

📝 Summary

Summary by CodeRabbit

  • New Features
    • Apple Pay and Google Pay buttons support a disabled option that ignores taps without changing their appearance.
    • Button components and related prop and style types are available as package exports.
  • Improvements
    • Pass payment handlers directly to onPress; callback wrappers are no longer required. Wrapped handlers remain supported but produce a development warning and TypeScript error.
    • Buttons render nothing with a development warning on unsupported platforms.
    • Google Pay radius values are measured in dp.
    • On iOS, the native button is recreated only when its type or style changes.

The PR adds exported Apple Pay and Google Pay React wrappers with direct handlers, disabled-state handling, and unsupported-platform guards. It updates iOS button reuse and Android radius conversion, adds tests, and revises documentation and examples.

Changes: Pay button wrappers and native behavior

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: Normal

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
Loading

Possibly related issues

Possibly related PRs

Merge Risk: Minimal · up to 3accd

The pay-button changes are ready to merge after normal checks.

Pre-merge checks: Passed 5 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning 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 surv… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 5 passed
Check name Status Explanation
Title check Passed 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 ch…
Description check Passed 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, …
Linked Issues check Passed Directly linked issue #21 has three acceptance criteria. All three are met by the PR summary and the tests it reports.

[#21] Plain onPress without callback(): ApplePayButton and `GooglePayButto…
Out of Scope Changes check Passed Every changed area maps to issue #21 or supports its API.

- Wrapper components, usePayButtonPress, and the re-exports in index.ts: implement the wrapper requirement.
- Removal of hybridRef as a…
Security Check Passed 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 do…
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 #21 has three acceptance criteria. All three are met by the PR summary and the tests it reports.

[#21] Plain onPress without callback(): ApplePayButton and GooglePayButton are exported React wrappers. usePayButtonPress wraps the handler with callback() once and reads the latest handler at tap time. index.ts re-exports the wrappers. README, docs and examples no longer use callback(). Render tests in PayButtons.test.tsx cover handler updates.

[#21] Changing only onPress does not create a new PKPaymentButton: HybridApplePayButton stores the type and style used to build the button. afterUpdate() rebuilds only when one of them changes. HybridApplePayButtonTests (3 tests) check reuse on onPress-only change, rebuild on type or style change, and that a tap calls the latest onPress.

[#21] Other platform renders a no-op: each wrapper returns null with a __DEV__ warning on the unsupported platform. Tests cover this.

[#21] disabled prop: taps are ignored in usePayButtonPress. 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] Android radius: cornerRadiusPx converts dp to px. GooglePayButtonFactoryTest covers scaling, zero, and rounding.

Optional items (cornerRadius, Apple Pay automatic style) 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 #21 or supports its API.

  • Wrapper components, usePayButtonPress, and the re-exports in index.ts: implement the wrapper requirement.
  • Removal of hybridRef as 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 HybridApplePayButton change and HybridApplePayButtonTests: implement the rebuild requirement and test it.
  • Android cornerRadiusPx and its unit test: implement the radius requirement (issue item 4).
  • jest.config.js *.test.tsx match: 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.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pre-merge checks failed. Please resolve the failing checks before merging.

@jkasprzyk17 jkasprzyk17 changed the title feat!: ship JS wrappers for the pay buttons; keep PKPaymentButton across re-renders feat!: add JS wrappers for the pay buttons Oct 27, 2026
@jkasprzyk17

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@jkasprzyk17

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.


Your included review limit is currently reached under our Fair Usage Limits Policy. Your current included review allowance is based on your included PR review attempts over the past 7 days. This review may still proceed through usage-based billing if eligible. Your next included review will be available in 14 minutes.

@jkasprzyk17

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@jkasprzyk17
jkasprzyk17 merged commit 7d336b6 into main Oct 27, 2026
7 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Oct 27, 2026
3 tasks done
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.

Ship JS wrappers for the pay buttons; stop rebuilding PKPaymentButton on every prop update

1 participant