React Native (expo-screen-orientation): Unable to Listen for Orientation Change in iOS

My issue

I cannot get the ScreenOrientation.addOrientationChangeListener to trigger on my iOS devices. It works fine on Android.

How to solve this question

The example below is my best effort to demonstrate my issue. If someone could help me trigger the orientationListener() in this code, using an iOS device, that would solve my problem.

Any advice or suggestions where to look are greatly appreciated 🙂

Gif displaying my issue

Details of my issue

I have a useEffect() where I implement the ScreenOrientation.addOrientationChangeListener(). When triggered it should trigger the orientationListener(). This works in Android but not iOS.

What does work on my iOS is, if I comment out my useEffect, I have a button that uses ScreenOrientation.getOrientationAsync() to populate my orientation. I can change the orientation of my device press this button and get the correct orientation on my iOS and Android. I am not sure exactly what this tells me but it makes me optimistic that there is a solution to the listener issue I am having.

My research

I have found this post (/a/76683420/11925053) and corresponding GitHub issue using ScreenOrientation.unlockAsync() , but that has also yeilded no success on my part. I have tried various variations of placing this in my useEffect or triggered by a button. I have also tried variations of modifying my app.json to start with a postion or default.

Code

import React, { useEffect, useState } from "react";
import { StyleSheet, Text, View, TouchableOpacity } from "react-native";
import * as ScreenOrientation from "expo-screen-orientation";

export default function Orientation06() {
  const [orientation, setOrientation] = useState("Unknown");

  useEffect(() => {
    const startListeningToOrientation = async () => {
      await ScreenOrientation.addOrientationChangeListener(orientationListener);
      console.log("in listeningToOrientation");
    };

    startListeningToOrientation();
  });

  const checkOrientation = async () => {
    console.log("in checkOrientation");
    const orientation = await ScreenOrientation.getOrientationAsync();
    setOrientation(orientation);
    console.log(`orientation is ${orientation}`);
  };

  const orientationListener = (o) => {
    console.log("in orientationListener 🔔");
    setOrientation(o.orientationInfo.orientation);
  };

  return (
    <View style={styles.container}>
      <Text style={styles.text}>Current Orientation:</Text>
      <Text style={styles.orientation}>{orientation}</Text>
      <TouchableOpacity
        style={styles.touchOpNav}
        onPress={() => checkOrientation()}
      >
        <Text style={styles.txtTouchOpNav}>Check orientation </Text>
      </TouchableOpacity>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "#f5f5f5",
  },
  text: {
    fontSize: 24,
    fontWeight: "bold",
  },
  orientation: {
    fontSize: 32,
    marginTop: 20,
    color: "#007AFF",
  },
  touchOpNav: {
    backgroundColor: "black",
    padding: 5,
    width: 250,
    borderRadius: 12,
    marginBottom: 1,
  },
  txtTouchOpNav: {
    color: "gray",
    alignSelf: "center",
    fontSize: 20,
  },
});

app.json

{
  "expo": {
    "name": "native-stuff-reducer-array",
    "slug": "native-stuff-reducer-array",
    "version": "1.0.0",
    "orientation": "default",
    "icon": "./assets/icon.png",
    "userInterfaceStyle": "light",
    "newArchEnabled": true,
    "splash": {
      "image": "./assets/splash-icon.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "ios": {
      "supportsTablet": true
    },
    "android": {
      "adaptiveIcon": {
        "foregroundImage": "./assets/adaptive-icon.png",
        "backgroundColor": "#ffffff"
      }
    },
    "web": {
      "favicon": "./assets/favicon.png"
    },
    "plugins": [
      "expo-video",
      [
        "expo-screen-orientation",
        {
          "initialOrientation": "DEFAULT"
        }
      ]
    ]
  }
}

You can configure expo-screen-orientation using its built-in config plugin if you use config plugins in your project (EAS Build or npx expo run:[android|ios]). The plugin allows you to configure various properties that cannot be set at runtime and require building a new app binary to take effect.

App.json

{
   "expo": {
   "ios": {
     "requireFullScreen": true
   },
   "plugins": [
     [
       "expo-screen-orientation",
       {
          "initialOrientation": "DEFAULT"
       }
     ]
   ]
  }
}

npx expo install expo-screen-orientation

For more detail Visit Expo Orientation

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

React Native (expo-screen-orientation): Unable to Listen for Orientation Change in iOS

My issue

I cannot get the ScreenOrientation.addOrientationChangeListener to trigger on my iOS devices. It works fine on Android.

How to solve this question

The example below is my best effort to demonstrate my issue. If someone could help me trigger the orientationListener() in this code, using an iOS device, that would solve my problem.

Any advice or suggestions where to look are greatly appreciated 🙂

Gif displaying my issue

Details of my issue

I have a useEffect() where I implement the ScreenOrientation.addOrientationChangeListener(). When triggered it should trigger the orientationListener(). This works in Android but not iOS.

What does work on my iOS is, if I comment out my useEffect, I have a button that uses ScreenOrientation.getOrientationAsync() to populate my orientation. I can change the orientation of my device press this button and get the correct orientation on my iOS and Android. I am not sure exactly what this tells me but it makes me optimistic that there is a solution to the listener issue I am having.

My research

I have found this post (/a/76683420/11925053) and corresponding GitHub issue using ScreenOrientation.unlockAsync() , but that has also yeilded no success on my part. I have tried various variations of placing this in my useEffect or triggered by a button. I have also tried variations of modifying my app.json to start with a postion or default.

Code

import React, { useEffect, useState } from "react";
import { StyleSheet, Text, View, TouchableOpacity } from "react-native";
import * as ScreenOrientation from "expo-screen-orientation";

export default function Orientation06() {
  const [orientation, setOrientation] = useState("Unknown");

  useEffect(() => {
    const startListeningToOrientation = async () => {
      await ScreenOrientation.addOrientationChangeListener(orientationListener);
      console.log("in listeningToOrientation");
    };

    startListeningToOrientation();
  });

  const checkOrientation = async () => {
    console.log("in checkOrientation");
    const orientation = await ScreenOrientation.getOrientationAsync();
    setOrientation(orientation);
    console.log(`orientation is ${orientation}`);
  };

  const orientationListener = (o) => {
    console.log("in orientationListener 🔔");
    setOrientation(o.orientationInfo.orientation);
  };

  return (
    <View style={styles.container}>
      <Text style={styles.text}>Current Orientation:</Text>
      <Text style={styles.orientation}>{orientation}</Text>
      <TouchableOpacity
        style={styles.touchOpNav}
        onPress={() => checkOrientation()}
      >
        <Text style={styles.txtTouchOpNav}>Check orientation </Text>
      </TouchableOpacity>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "#f5f5f5",
  },
  text: {
    fontSize: 24,
    fontWeight: "bold",
  },
  orientation: {
    fontSize: 32,
    marginTop: 20,
    color: "#007AFF",
  },
  touchOpNav: {
    backgroundColor: "black",
    padding: 5,
    width: 250,
    borderRadius: 12,
    marginBottom: 1,
  },
  txtTouchOpNav: {
    color: "gray",
    alignSelf: "center",
    fontSize: 20,
  },
});

app.json

{
  "expo": {
    "name": "native-stuff-reducer-array",
    "slug": "native-stuff-reducer-array",
    "version": "1.0.0",
    "orientation": "default",
    "icon": "./assets/icon.png",
    "userInterfaceStyle": "light",
    "newArchEnabled": true,
    "splash": {
      "image": "./assets/splash-icon.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "ios": {
      "supportsTablet": true
    },
    "android": {
      "adaptiveIcon": {
        "foregroundImage": "./assets/adaptive-icon.png",
        "backgroundColor": "#ffffff"
      }
    },
    "web": {
      "favicon": "./assets/favicon.png"
    },
    "plugins": [
      "expo-video",
      [
        "expo-screen-orientation",
        {
          "initialOrientation": "DEFAULT"
        }
      ]
    ]
  }
}

You can configure expo-screen-orientation using its built-in config plugin if you use config plugins in your project (EAS Build or npx expo run:[android|ios]). The plugin allows you to configure various properties that cannot be set at runtime and require building a new app binary to take effect.

App.json

{
   "expo": {
   "ios": {
     "requireFullScreen": true
   },
   "plugins": [
     [
       "expo-screen-orientation",
       {
          "initialOrientation": "DEFAULT"
       }
     ]
   ]
  }
}

npx expo install expo-screen-orientation

For more detail Visit Expo Orientation

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

React Native (expo-screen-orientation): Unable to Listen for Orientation Change in iOS

My issue

I cannot get the ScreenOrientation.addOrientationChangeListener to trigger on my iOS devices. It works fine on Android.

How to solve this question

The example below is my best effort to demonstrate my issue. If someone could help me trigger the orientationListener() in this code, using an iOS device, that would solve my problem.

Any advice or suggestions where to look are greatly appreciated 🙂

Gif displaying my issue

Details of my issue

I have a useEffect() where I implement the ScreenOrientation.addOrientationChangeListener(). When triggered it should trigger the orientationListener(). This works in Android but not iOS.

What does work on my iOS is, if I comment out my useEffect, I have a button that uses ScreenOrientation.getOrientationAsync() to populate my orientation. I can change the orientation of my device press this button and get the correct orientation on my iOS and Android. I am not sure exactly what this tells me but it makes me optimistic that there is a solution to the listener issue I am having.

My research

I have found this post (/a/76683420/11925053) and corresponding GitHub issue using ScreenOrientation.unlockAsync() , but that has also yeilded no success on my part. I have tried various variations of placing this in my useEffect or triggered by a button. I have also tried variations of modifying my app.json to start with a postion or default.

Code

import React, { useEffect, useState } from "react";
import { StyleSheet, Text, View, TouchableOpacity } from "react-native";
import * as ScreenOrientation from "expo-screen-orientation";

export default function Orientation06() {
  const [orientation, setOrientation] = useState("Unknown");

  useEffect(() => {
    const startListeningToOrientation = async () => {
      await ScreenOrientation.addOrientationChangeListener(orientationListener);
      console.log("in listeningToOrientation");
    };

    startListeningToOrientation();
  });

  const checkOrientation = async () => {
    console.log("in checkOrientation");
    const orientation = await ScreenOrientation.getOrientationAsync();
    setOrientation(orientation);
    console.log(`orientation is ${orientation}`);
  };

  const orientationListener = (o) => {
    console.log("in orientationListener 🔔");
    setOrientation(o.orientationInfo.orientation);
  };

  return (
    <View style={styles.container}>
      <Text style={styles.text}>Current Orientation:</Text>
      <Text style={styles.orientation}>{orientation}</Text>
      <TouchableOpacity
        style={styles.touchOpNav}
        onPress={() => checkOrientation()}
      >
        <Text style={styles.txtTouchOpNav}>Check orientation </Text>
      </TouchableOpacity>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "#f5f5f5",
  },
  text: {
    fontSize: 24,
    fontWeight: "bold",
  },
  orientation: {
    fontSize: 32,
    marginTop: 20,
    color: "#007AFF",
  },
  touchOpNav: {
    backgroundColor: "black",
    padding: 5,
    width: 250,
    borderRadius: 12,
    marginBottom: 1,
  },
  txtTouchOpNav: {
    color: "gray",
    alignSelf: "center",
    fontSize: 20,
  },
});

app.json

{
  "expo": {
    "name": "native-stuff-reducer-array",
    "slug": "native-stuff-reducer-array",
    "version": "1.0.0",
    "orientation": "default",
    "icon": "./assets/icon.png",
    "userInterfaceStyle": "light",
    "newArchEnabled": true,
    "splash": {
      "image": "./assets/splash-icon.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "ios": {
      "supportsTablet": true
    },
    "android": {
      "adaptiveIcon": {
        "foregroundImage": "./assets/adaptive-icon.png",
        "backgroundColor": "#ffffff"
      }
    },
    "web": {
      "favicon": "./assets/favicon.png"
    },
    "plugins": [
      "expo-video",
      [
        "expo-screen-orientation",
        {
          "initialOrientation": "DEFAULT"
        }
      ]
    ]
  }
}

You can configure expo-screen-orientation using its built-in config plugin if you use config plugins in your project (EAS Build or npx expo run:[android|ios]). The plugin allows you to configure various properties that cannot be set at runtime and require building a new app binary to take effect.

App.json

{
   "expo": {
   "ios": {
     "requireFullScreen": true
   },
   "plugins": [
     [
       "expo-screen-orientation",
       {
          "initialOrientation": "DEFAULT"
       }
     ]
   ]
  }
}

npx expo install expo-screen-orientation

For more detail Visit Expo Orientation

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật