AlwaysLoveme / capacitor-plugin-safe-area

capacitor plugin to get safeArea info on Android and IOS, support Capacitor6
MIT License
66 stars 14 forks source link

Not receiving correct values upon app launch #26

Open tybro0103 opened 10 months ago

tybro0103 commented 10 months ago

I can't seem to figure out how to reliably get the correct values upon launch.

I'm doing this:

const listenForSafeArea = async (store) => {
  const {insets} = await SafeArea.getSafeAreaInsets();
  store.dispatch(DeviceDuck.Ax.setSafeArea(insets));
  SafeArea.addListener('safeAreaChanged', ({insets}) => {
    store.dispatch(DeviceDuck.Ax.setSafeArea(insets));
  });
};
listenForSafeArea();

Sometimes it works, and sometimes it doesn't. As soon as something causes the insets to change, it works, but that first call to SafeArea.getSafeAreaInsets sometimes has the values and sometimes doesn't.

Is there a particular event I need to wait for before that first call?

I'm experiencing this in iOS. Haven't tried Android.