Skip to content

Fix view controller presentation by using displayController parameter#463

Open
sriharsha-y wants to merge 1 commit intorazorpay:masterfrom
sriharsha-y:f/ios-view-controller-fix
Open

Fix view controller presentation by using displayController parameter#463
sriharsha-y wants to merge 1 commit intorazorpay:masterfrom
sriharsha-y:f/ios-view-controller-fix

Conversation

@sriharsha-y
Copy link

Fixes #461

Problem:
The Flutter plugin was calling razorpay.open(options) without the displayController parameter, forcing the native Razorpay SDK to use the root view controller for presentation. This fails when the root VC has already presented another view controller, causing the error: "Attempt to present on which is already presenting"

This occurs in any scenario where modal presentations exist in the view hierarchy (e.g., mixed React Native + Flutter projects, or apps with complex navigation patterns).

Solution:
The native Razorpay iOS SDK (razorpay-pod) supports an optional displayController parameter in its open method to specify which view controller should present the payment interface. This fix leverages that capability:

  • Added presentedViewControllerFromRoot() to find the topmost presented view controller in the hierarchy
  • Modified razorpay.open() call to pass this controller via displayController parameter when available
  • Falls back to original call without displayController if no presented VC exists

This properly utilizes the native SDK's intended flexibility and fixes presentation failures in complex view hierarchies.

Fixes razorpay#461

Problem:
The Flutter plugin was calling razorpay.open(options) without the
displayController parameter, forcing the native Razorpay SDK to use
the root view controller for presentation. This fails when the root
VC has already presented another view controller, causing the error:
"Attempt to present on <UIViewController> which is already presenting"

This occurs in any scenario where modal presentations exist in the
view hierarchy (e.g., mixed React Native + Flutter projects, or apps
with complex navigation patterns).

Solution:
The native Razorpay iOS SDK (razorpay-pod) supports an optional
displayController parameter in its open method to specify which view
controller should present the payment interface. This fix leverages
that capability:

- Added presentedViewControllerFromRoot() to find the topmost presented
  view controller in the hierarchy
- Modified razorpay.open() call to pass this controller via displayController
  parameter when available
- Falls back to original call without displayController if no presented
  VC exists

This properly utilizes the native SDK's intended flexibility and fixes
presentation failures in complex view hierarchies.
@sriharsha-y sriharsha-y marked this pull request as draft October 30, 2025 10:17
@sriharsha-y sriharsha-y marked this pull request as ready for review October 31, 2025 05:17
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.

Can't open Razorpay in mixed React Native & Flutter Project [iOS]

1 participant