Swift / React Native How to know split view / slide over app's position relative to the whole screen?

135 Views Asked by At

I'm making a react-native based app, and I can partially use Swift code by react-native's NativeModule feature.

My app will be used as Split view / Slide over mode in iPad, and I want to know if my app is in the left-side, right-side, or Slide-over.

I could get width and height, also origin (CGPoint) by this code.

let window = UIApplication.shared.windows.first

// Then getting X, Y like this...
window.frame.origin.x

Now my app has only one webview, made by react-native-webview. So I guess, since the webview is the whole content of the app, and it fills app 100%, so it always returns app.

I want to know, not in webView's perspective, but in app's perpective, the POSITION relative to the screen.

For example, if my iPad width is 1400, and if my app is on the half right side, x should be 700. And if it is on left side, it should be 0.

I really struggled this, but couldn't find any solution. FYI, I drawed a diagram for this question.

diagram

As I wrote on the above, I tried UIApplication.shared.windows.first.frame. But it only show the CGPoint of webview, not app relative to the screen.

There is no API for getting 'X' or 'LEFT' in react-native-dimension too. onLayout also not helpful.

0

There are 0 best solutions below