Skip to content

Fix IAM display rendering issues on foldable Android devices (Samsung Galaxy Fold/Flip)#2597

Draft
abdulraqeeb33 wants to merge 1 commit intomainfrom
cursor/iam-display-foldable-devices-d6f1
Draft

Fix IAM display rendering issues on foldable Android devices (Samsung Galaxy Fold/Flip)#2597
abdulraqeeb33 wants to merge 1 commit intomainfrom
cursor/iam-display-foldable-devices-d6f1

Conversation

@abdulraqeeb33
Copy link
Copy Markdown
Contributor

Description

One Line Summary

Fix In-App Message (IAM) display rendering issues on foldable Android devices by detecting screen size changes and using modern WindowMetrics API.

Details

Motivation

Foldable Android devices like Samsung Galaxy Fold and Flip experience IAM rendering issues when users fold/unfold their devices. The IAM content may appear cut-off, mispositioned, or incorrectly sized because:

  1. Screen size changes without orientation change: When a foldable device transitions between its cover screen and main screen (or vice versa), the screen dimensions change dramatically without triggering an orientation change event.

  2. Deprecated APIs: The SDK was using deprecated defaultDisplay.getSize() APIs that don't properly handle multi-window and foldable device scenarios on Android 11+.

  3. Missing configuration detection: The SDK only listened for CONFIG_ORIENTATION changes, missing the CONFIG_SCREEN_SIZE changes that foldable devices trigger.

Scope

What is affected:

  • In-App Message display on foldable devices (Samsung Galaxy Fold, Flip, and similar devices)
  • Window dimension calculations on Android 11+ (API 30+)

What is NOT affected:

  • IAM behavior on non-foldable devices (no functional change)
  • IAM behavior on Android versions below API 30 (existing behavior preserved)
  • Other SDK features (notifications, outcomes, sessions, etc.)

Technical Changes

  1. ViewUtils.kt:

    • Added getWindowHeightAPI30Plus() using WindowMetrics API for accurate dimensions
    • Added getWindowWidthAPI30Plus() for consistent width calculations
    • Updated getFullbleedWindowWidth() to use WindowMetrics on API 30+
    • Added @Suppress("DEPRECATION") annotation for backward-compatible code paths
  2. ApplicationService.kt:

    • Added screen size change detection in onConfigurationChanged callback
    • Tracks screenWidthDp and screenHeightDp to detect fold/unfold events
    • New onScreenSizeChanged() method triggers IAM view recreation
    • Fires onActivityStopped/onActivityAvailable lifecycle events to recalculate IAM dimensions
  3. WebViewManager.kt:

    • Updated comment to clarify that the same code path handles both rotation and fold/unfold events

Testing

Unit testing

Existing ApplicationServiceTests pass. The screen size change detection is triggered through the same lifecycle events that are already tested for orientation changes.

Manual testing

Recommended testing scenarios:

  1. Display an IAM on a foldable device in folded state, then unfold - IAM should resize correctly
  2. Display an IAM on a foldable device in unfolded state, then fold - IAM should resize correctly
  3. Test all IAM positions (TOP_BANNER, BOTTOM_BANNER, CENTER_MODAL, FULL_SCREEN) during fold/unfold
  4. Verify no regression on non-foldable devices

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item
Open in Web Open in Cursor 

This commit addresses rendering issues with In-App Messages (IAM) on
foldable Android devices like Samsung Galaxy Fold/Flip.

Root cause:
- Foldable devices change screen size without triggering orientation changes
- The SDK only listened for CONFIG_ORIENTATION changes, missing fold/unfold events
- ViewUtils used deprecated APIs that don't properly handle multi-window scenarios

Changes:
1. ViewUtils.kt:
   - Added API 30+ (Android 11+) implementation using WindowMetrics API
   - getWindowHeight() now uses currentWindowMetrics for accurate dimensions
   - getWindowWidth() and getFullbleedWindowWidth() updated similarly
   - Properly handles foldable device screen size changes

2. ApplicationService.kt:
   - Added screen size change detection via onConfigurationChanged
   - Tracks screenWidthDp/screenHeightDp to detect fold/unfold events
   - New onScreenSizeChanged() method triggers IAM view recreation
   - Fires onActivityStopped/onActivityAvailable to recalculate IAM dimensions

3. WebViewManager.kt:
   - Updated comment to clarify fold/unfold handling alongside rotation

The fix ensures IAMs are properly resized and repositioned when users
fold/unfold their devices, preventing cut-off content and mispositioned
messages.

Co-authored-by: abdul <abdul@onesignal.com>
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.

2 participants