Skip to content

Conversation

joshdholtz
Copy link
Member

@joshdholtz joshdholtz commented Sep 11, 2025

Fixes #1366

Summary

  • Fixes styling timing issue where styles applied to RevenueCatUI.Paywall component were not being applied immediately
  • The problem was that the paywall's native view was only added to the view hierarchy during layoutSubviews, which happens after React Native applies styles to the wrapper view
  • Move paywall view setup to initialization time to ensure styles are applied correctly

Changes

  • Move paywall view setup to initialization time in setupPaywallView method
  • Set up view constraints immediately when the wrapper is created
  • Defer only the view controller hierarchy setup until layoutSubviews

Test plan

  • Test that styles like paddingTop: 32 are applied immediately to PaywallView without needing loading states or timeouts
  • Verify that existing paywall functionality (purchase flows, callbacks) continues to work correctly
  • Test on both iOS simulator and device
  • Confirm no layout issues or constraint conflicts

@joshdholtz joshdholtz added the pr:fix A bug fix label Sep 11, 2025
@joshdholtz joshdholtz force-pushed the fix-paywall-styling-timing-issue branch from 5f7b46c to 5f41a62 Compare September 11, 2025 18:36
Fixes an issue where styles applied to RevenueCatUI.Paywall component
were not being applied immediately. The problem was that the paywall's
native view setup was deferred until layoutSubviews, causing a timing
issue with React Native's style application.

This solution preserves the original view hierarchy timing while forcing
immediate layout updates when React Native applies style changes, with
robust protection against infinite layout loops.

Changes:
- Override reactSetFrame, setBounds, and setFrame methods
- Call setNeedsLayout + layoutIfNeeded to force immediate layout updates
- Add isInLayoutUpdate flag to prevent infinite layout loops
- Use dispatch_async to break synchronous recursion chains
- Only trigger layout for actual frame/bounds changes
- Preserve original view controller hierarchy setup timing

This approach is safer than restructuring the view hierarchy timing as it:
- Maintains SwiftUI environment context
- Preserves safe area and layout guide behavior
- Works with React Native's layout system
- Protected against infinite layout loops

Fixes #1366

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@joshdholtz joshdholtz force-pushed the fix-paywall-styling-timing-issue branch from 5f41a62 to 8097087 Compare September 11, 2025 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Passing styles to Paywall in react-native-purchases-ui not working

1 participant