Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insets on iOS are not calculated correctly #389

Open
yousefelgoharyx opened this issue Dec 3, 2024 · 10 comments
Open

Insets on iOS are not calculated correctly #389

yousefelgoharyx opened this issue Dec 3, 2024 · 10 comments

Comments

@yousefelgoharyx
Copy link
Contributor

Description

on iOS on a real device, using the old arch and expo-video causes the insets to become zero when the app goes in the background or actually when any layout change happens

Changing the implementation of getInsets function to this solves the issue

- (Insets)getInsets {
   UIWindowScene *windowScene = (UIWindowScene *)UIApplication.sharedApplication.connectedScenes.allObjects.firstObject;
    if (windowScene) {
        UIWindow *window = windowScene.windows.firstObject;
        if (window) {
            UIEdgeInsets safeArea = window.safeAreaInsets;
            NSLog(@"🦄 Insets Debug: top:%f, bottom:%f, left:%f, right:%f", 
                  safeArea.top, safeArea.bottom, safeArea.left, safeArea.right);
            return {(int)safeArea.top, (int)safeArea.bottom, (int)safeArea.left, (int)safeArea.right};
        }
    }
    
    // Fallback to root view controller
    UIViewController *rootViewController = UIApplication.sharedApplication.delegate.window.rootViewController;
    if (rootViewController) {
        UIEdgeInsets safeArea = rootViewController.view.safeAreaInsets;
        NSLog(@"🦄 Fallback Insets: top:%f, bottom:%f, left:%f, right:%f", 
              safeArea.top, safeArea.bottom, safeArea.left, safeArea.right);
        return {(int)safeArea.top, (int)safeArea.bottom, (int)safeArea.left, (int)safeArea.right};
    }
    
    NSLog(@"🦄 WARNING: Could not retrieve safe area insets");
    return {0, 0, 0, 0};
}

However, I'm not an iOS expert so I decided to just open an issue not a PR

Steps to Reproduce

  • Init empty expo project using old arch
  • install expo video
  • render a video and a view with the top inset height
  • make the app in the background
  • make the app in the foreground

once the app gets in the foreground, the insets will become 0

Snack or Repository Link (Optional)

No response

Unistyles Version

2.20.0

React Native Version

0.76.3

Platforms

iOS

Expo

Yes

@jpudysz
Copy link
Owner

jpudysz commented Dec 3, 2024

Thanks for the PR-issue ☺️

Do you have any repo where I can also debug it? Maybe I can port it to 3.x too.

By the way, I will have more time to review it during the weekend.

@yousefelgoharyx
Copy link
Contributor Author

https://github.com/yousefelgoharyx/unistyles-insets
here you go
I'm testing on iPhone 15 Pro iOS 18.1.1

@jpudysz
Copy link
Owner

jpudysz commented Dec 3, 2024

Many thanks! Will get back to you later this week

@yousefelgoharyx
Copy link
Contributor Author

Awesome
really appreciate your hard work!

@bernardogeneroso
Copy link

Hey.

The same behavior is observed on Android.
Thank you!

@jpudysz
Copy link
Owner

jpudysz commented Dec 9, 2024

Hey @yousefelgoharyx I've tried your demo and I can't reproduce 🥹

My steps:

  • install demo
  • run it on iOS
  • go to "Explore" tab (video is rendered)
  • Go to the background (with breakpoint in Obj-c code)
  • Go to the foreground (with breakpoint in Obj-c code)

Result:
Same values for both foreground & background.

Do I need to do anything else?
I'm running it on iPhone 16 Pro Max (iOS 18.0)

@yousefelgoharyx
Copy link
Contributor Author

Sorry for late response
I'll push a change changing the lock file even though I doubt it'd do anything
But here's a recording
Do you mean iOS 18.x.x or exactly iOS 18.0.0
Because it might be related to a higher version of iOS
https://github.com/user-attachments/assets/9691bbed-8f0c-4fce-a1f8-9531ff3b1739

@yousefelgoharyx
Copy link
Contributor Author

I'll try it out on other iPhones we I can, maybe something is wrong with my device since I can't reproduce it on simulator

@jpudysz
Copy link
Owner

jpudysz commented Dec 10, 2024

Let me try with real device. Maybe that's the case!

@yousefelgoharyx
Copy link
Contributor Author

ooh yes, i mentioned that in the original comment but probably i should've stressed on the issue being related to real devices haha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants