Skip to content

fix(android): wrap context with AppCompat theme for Google Pay button#2321

Merged
jonasbark merged 2 commits intoflutter-stripe:mainfrom
realmeylisdev:fix/google-pay-button-appcompat-theme
Feb 3, 2026
Merged

fix(android): wrap context with AppCompat theme for Google Pay button#2321
jonasbark merged 2 commits intoflutter-stripe:mainfrom
realmeylisdev:fix/google-pay-button-appcompat-theme

Conversation

@realmeylisdev
Copy link
Copy Markdown
Contributor

@realmeylisdev realmeylisdev commented Jan 29, 2026

Summary

The Google Pay PayButton uses AppCompatTextView internally, which requires a Theme.AppCompat theme. When the host app uses a non-AppCompat theme (e.g., Theme.MaterialComponents or other themes), this causes errors:

E/ThemeUtils: View class android.support.v7.widget.AppCompatTextView is an AppCompat 
widget that can only be used with a Theme.AppCompat theme (or descendant).

Root cause: ReactContext extended ContextWrapper(currentActivity) directly, which doesn't guarantee AppCompat theme attributes are available.

Fix: Changed ReactContext to extend ContextThemeWrapper with an explicit Theme_AppCompat_Light_NoActionBar theme, ensuring all platform views have access to AppCompat theme attributes regardless of the host app's theme.

Test plan

  • Build the example app and verify Google Pay button displays without AppCompat theme errors
  • Test on devices/emulators that were previously showing the error
  • Verify Google Pay button still functions correctly (onPressed callback works)

Summary by CodeRabbit

  • Refactor
    • Updated React Context initialization to use enhanced theme support, improving the application's theming architecture.

Fixes flutter-stripe#1907

The Google Pay PayButton uses AppCompatTextView internally, which
requires a Theme.AppCompat theme. When the host app uses a non-AppCompat
theme, this causes errors like:
"View class android.support.v7.widget.AppCompatTextView is an AppCompat
widget that can only be used with a Theme.AppCompat theme"

Changed ReactContext to extend ContextThemeWrapper with an explicit
AppCompat theme instead of plain ContextWrapper, ensuring all platform
views have access to AppCompat theme attributes.
@remonh87 remonh87 requested a review from jonasbark February 3, 2026 10:48
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 3, 2026

📝 Walkthrough

Walkthrough

Superclass changed from ContextWrapper to ContextThemeWrapper in ReactContext, applying Theme.AppCompat to address Google Pay button rendering and theme inflation errors. Single file modification with updated imports.

Changes

Cohort / File(s) Summary
ReactContext Superclass Update
packages/stripe_android/android/src/main/kotlin/com/facebook/react/bridge/ReactContext.kt
Replaced ContextWrapper superclass with ContextThemeWrapper, applying Theme_AppCompat_Light_NoActionBar theme to resolve theme inflation errors in Google Pay button rendering. Updated corresponding imports.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A theme applied with AppCompat light,
The Google button now renders right,
No more warnings in the logs we see,
Just clean code and harmony! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The PR addresses the core AppCompat theme requirement from #1907, but lacks evidence of callback testing and regression-proofing mentioned in objectives. Verify that onPressed callback functionality works and confirm regression tests are included or planned for the Samsung Galaxy S23 scenario.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: wrapping context with AppCompat theme to fix Google Pay button rendering issues.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the Google Pay button theme issue; no unrelated modifications detected in the ReactContext file.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

@jonasbark
Copy link
Copy Markdown
Member

thanks!

@jonasbark jonasbark merged commit 8223938 into flutter-stripe:main Feb 3, 2026
3 of 6 checks passed
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.

[BUG] PlatformPayButton for Google Pay

3 participants