├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── android ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── org │ └── wonday │ └── orientation │ ├── OrientationActivityLifecycle.java │ ├── OrientationListeners.java │ ├── OrientationModule.java │ └── OrientationPackage.java ├── example ├── .buckconfig ├── .eslintrc.js ├── .flowconfig ├── .gitattributes ├── .gitignore ├── .prettierrc.js ├── .watchmanconfig ├── App.js ├── __tests__ │ └── App-test.js ├── android │ ├── app │ │ ├── BUCK │ │ ├── build.gradle │ │ ├── build_defs.bzl │ │ ├── debug.keystore │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ ├── proguard-rules.pro │ │ └── src │ │ │ ├── debug │ │ │ ├── AndroidManifest.xml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── ReactNativeFlipper.java │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ ├── MainActivity.java │ │ │ │ └── MainApplication.java │ │ │ └── res │ │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ └── values │ │ │ ├── strings.xml │ │ │ └── styles.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── app.json ├── babel.config.js ├── index.js ├── ios │ ├── Podfile │ ├── Podfile.lock │ ├── example-tvOS │ │ └── Info.plist │ ├── example-tvOSTests │ │ └── Info.plist │ ├── example.xcodeproj │ │ └── project.pbxproj │ ├── example │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Images.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ │ └── Contents.json │ │ ├── Info.plist │ │ ├── LaunchScreen.storyboard │ │ └── main.m │ └── exampleTests │ │ ├── Info.plist │ │ └── exampleTests.m ├── metro.config.js ├── metro.config.windows.js ├── package.json ├── react-native.config.js └── windows │ ├── .gitignore │ ├── example.sln │ └── example │ ├── .gitignore │ ├── App.cpp │ ├── App.h │ ├── App.idl │ ├── App.xaml │ ├── Assets │ ├── LockScreenLogo.scale-200.png │ ├── SplashScreen.scale-200.png │ ├── Square150x150Logo.scale-200.png │ ├── Square44x44Logo.scale-200.png │ ├── Square44x44Logo.targetsize-24_altform-unplated.png │ ├── StoreLogo.png │ └── Wide310x150Logo.scale-200.png │ ├── AutolinkedNativeModules.g.cpp │ ├── AutolinkedNativeModules.g.h │ ├── AutolinkedNativeModules.g.targets │ ├── MainPage.cpp │ ├── MainPage.h │ ├── MainPage.idl │ ├── MainPage.xaml │ ├── Package.appxmanifest │ ├── PropertySheet.props │ ├── ReactPackageProvider.cpp │ ├── ReactPackageProvider.h │ ├── example.vcxproj │ ├── example.vcxproj.filters │ ├── example_TemporaryKey.pfx │ ├── packages.config │ ├── pch.cpp │ └── pch.h ├── iOS ├── RCTOrientation.xcodeproj │ └── project.pbxproj └── RCTOrientation │ ├── Orientation.h │ └── Orientation.m ├── index.d.ts ├── index.js ├── package.json ├── react-native-orientation-locker.podspec ├── react-native.config.js ├── src ├── OrientationLocker.js ├── hooks │ ├── index.js │ ├── useDeviceOrientationChange.js │ ├── useLockListener.js │ └── useOrientationChange.js ├── orientation.android.js ├── orientation.ios.js ├── orientation.js ├── orientation.windows.js └── package.json └── windows ├── .gitignore ├── OrientationWindows.sln └── OrientationWindows ├── OrientationWindows.cpp ├── OrientationWindows.def ├── OrientationWindows.h ├── OrientationWindows.rc ├── OrientationWindows.vcxproj ├── OrientationWindows.vcxproj.filters ├── PropertySheet.props ├── ReactPackageProvider.cpp ├── ReactPackageProvider.h ├── ReactPackageProvider.idl ├── packages.config ├── pch.cpp ├── pch.h ├── readme.txt └── resource.h /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | xcuserdata/ 3 | xcshareddata/ 4 | contents.xcworkspacedata 5 | android/.gradle 6 | android/.project 7 | android/.settings 8 | .history 9 | .vs/ 10 | build 11 | ..* 12 | *~ 13 | nuget.exe 14 | yarn-error.log 15 | yarn.lock -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | !**/*.xcodeproj 7 | !**/*.pbxproj 8 | !**/*.xcworkspacedata 9 | !**/*.xcsettings 10 | !**/*.xcscheme 11 | *.pbxuser 12 | !default.pbxuser 13 | *.mode1v3 14 | !default.mode1v3 15 | *.mode2v3 16 | !default.mode2v3 17 | *.perspectivev3 18 | !default.perspectivev3 19 | xcuserdata 20 | *.xccheckout 21 | *.moved-aside 22 | DerivedData 23 | *.hmap 24 | *.ipa 25 | *.xcuserstate 26 | project.xcworkspace 27 | 28 | # Android/IJ 29 | # 30 | /build/ 31 | .idea 32 | .gradle 33 | local.properties 34 | 35 | # node.js 36 | # 37 | node_modules/ 38 | npm-debug.log 39 | yarn.lock 40 | yarn-error.log 41 | 42 | # others 43 | # 44 | .npmignore 45 | .buckconfig 46 | .flowconfig 47 | .gitattributes 48 | .gitignore 49 | .git 50 | .watchmanconfig 51 | .history 52 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Wonday (@wonday.org) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | def safeExtGet(prop, fallback) { 4 | rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback 5 | } 6 | 7 | android { 8 | compileSdkVersion safeExtGet('compileSdkVersion', 27) 9 | buildToolsVersion safeExtGet('buildToolsVersion', '27.0.3') 10 | 11 | defaultConfig { 12 | minSdkVersion safeExtGet('minSdkVersion', 16) 13 | targetSdkVersion safeExtGet('targetSdkVersion', 26) 14 | versionCode 1 15 | versionName "1.0" 16 | ndk { 17 | abiFilters "armeabi-v7a", "x86" 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation "com.facebook.react:react-native:${safeExtGet('reactNative', '+')}" 24 | } 25 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /android/src/main/java/org/wonday/orientation/OrientationActivityLifecycle.java: -------------------------------------------------------------------------------- 1 | package org.wonday.orientation; 2 | 3 | import android.app.Activity; 4 | import android.app.Application; 5 | import android.os.Bundle; 6 | import android.util.Log; 7 | 8 | import java.util.concurrent.atomic.AtomicInteger; 9 | 10 | public class OrientationActivityLifecycle implements Application.ActivityLifecycleCallbacks { 11 | private static final String TAG = "OrientationModule"; 12 | private static AtomicInteger activeCount = new AtomicInteger(0); 13 | private OrientationListeners orientationListeners; 14 | 15 | private static OrientationActivityLifecycle instance; 16 | 17 | public static OrientationActivityLifecycle getInstance() { 18 | if (instance == null) { 19 | instance = new OrientationActivityLifecycle(); 20 | } 21 | return instance; 22 | } 23 | 24 | private OrientationActivityLifecycle() {} 25 | 26 | public void registerListeners(OrientationListeners listener) { 27 | this.orientationListeners = listener; 28 | if (activeCount.get() == 1) { 29 | // Trigger start event 30 | orientationListeners.start(); 31 | } 32 | } 33 | 34 | @Override 35 | public void onActivityCreated(Activity activity, Bundle savedInstanceState) { 36 | Log.d(TAG, "onActivityCreated"); 37 | } 38 | 39 | @Override 40 | public void onActivityStarted(Activity activity) { 41 | Log.d(TAG, "onActivityStarted"); 42 | } 43 | 44 | @Override 45 | public void onActivityResumed(Activity activity) { 46 | Log.d(TAG, "onActivityResumed"); 47 | if (activeCount.incrementAndGet() == 1) { 48 | if (orientationListeners != null) { 49 | Log.d(TAG, "Start orientation"); 50 | orientationListeners.start(); 51 | } 52 | } 53 | } 54 | 55 | @Override 56 | public void onActivityPaused(Activity activity) { 57 | Log.d(TAG, "onActivityPaused"); 58 | } 59 | 60 | @Override 61 | public void onActivityStopped(Activity activity) { 62 | Log.d(TAG, "onActivityStopped"); 63 | if (activeCount.decrementAndGet() == 0) { 64 | if (orientationListeners != null) { 65 | orientationListeners.stop(); 66 | } 67 | } 68 | 69 | } 70 | 71 | @Override 72 | public void onActivitySaveInstanceState(Activity activity, Bundle outState) { 73 | Log.d(TAG, "onActivitySaveInstanceState"); 74 | } 75 | 76 | @Override 77 | public void onActivityDestroyed(Activity activity) { 78 | Log.d(TAG, "onActivityDestroyed"); 79 | if (activeCount.get() == 0) { 80 | if (orientationListeners != null) { 81 | orientationListeners.release(); 82 | } 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /android/src/main/java/org/wonday/orientation/OrientationListeners.java: -------------------------------------------------------------------------------- 1 | package org.wonday.orientation; 2 | 3 | interface OrientationListeners { 4 | void start(); 5 | 6 | void stop(); 7 | 8 | void release(); 9 | } 10 | -------------------------------------------------------------------------------- /android/src/main/java/org/wonday/orientation/OrientationPackage.java: -------------------------------------------------------------------------------- 1 | // 2 | // react-native-orientation-locker 3 | // 4 | // 5 | // Created by Wonday on 17/5/12. 6 | // Copyright (c) wonday.org All rights reserved. 7 | // 8 | 9 | package org.wonday.orientation; 10 | 11 | import com.facebook.react.ReactPackage; 12 | import com.facebook.react.bridge.JavaScriptModule; 13 | import com.facebook.react.bridge.NativeModule; 14 | import com.facebook.react.bridge.ReactApplicationContext; 15 | import com.facebook.react.uimanager.ViewManager; 16 | 17 | import java.util.Arrays; 18 | import java.util.Collections; 19 | import java.util.List; 20 | 21 | public class OrientationPackage implements ReactPackage { 22 | 23 | public OrientationPackage() { 24 | } 25 | 26 | @Override 27 | public List createNativeModules(ReactApplicationContext reactContext) { 28 | return Arrays.asList( 29 | new OrientationModule(reactContext) 30 | ); 31 | } 32 | 33 | 34 | public List> createJSModules() { 35 | return Collections.emptyList(); 36 | } 37 | 38 | @Override 39 | public List createViewManagers(ReactApplicationContext reactContext) { 40 | return Arrays.asList(); 41 | } 42 | } 43 | 44 | 45 | -------------------------------------------------------------------------------- /example/.buckconfig: -------------------------------------------------------------------------------- 1 | 2 | [android] 3 | target = Google Inc.:Google APIs:23 4 | 5 | [maven_repositories] 6 | central = https://repo1.maven.org/maven2 7 | -------------------------------------------------------------------------------- /example/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: '@react-native-community', 4 | }; 5 | -------------------------------------------------------------------------------- /example/.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | ; We fork some components by platform 3 | .*/*[.]android.js 4 | 5 | ; Ignore "BUCK" generated dirs 6 | /\.buckd/ 7 | 8 | ; Ignore polyfills 9 | node_modules/react-native/Libraries/polyfills/.* 10 | 11 | ; These should not be required directly 12 | ; require from fbjs/lib instead: require('fbjs/lib/warning') 13 | node_modules/warning/.* 14 | 15 | ; Flow doesn't support platforms 16 | .*/Libraries/Utilities/LoadingView.js 17 | 18 | [untyped] 19 | .*/node_modules/@react-native-community/cli/.*/.* 20 | 21 | [include] 22 | 23 | [libs] 24 | node_modules/react-native/interface.js 25 | node_modules/react-native/flow/ 26 | 27 | [options] 28 | emoji=true 29 | 30 | esproposal.optional_chaining=enable 31 | esproposal.nullish_coalescing=enable 32 | 33 | module.file_ext=.js 34 | module.file_ext=.json 35 | module.file_ext=.ios.js 36 | 37 | munge_underscores=true 38 | 39 | module.name_mapper='^react-native/\(.*\)$' -> '/node_modules/react-native/\1' 40 | module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '/node_modules/react-native/Libraries/Image/RelativeImageStub' 41 | 42 | suppress_type=$FlowIssue 43 | suppress_type=$FlowFixMe 44 | suppress_type=$FlowFixMeProps 45 | suppress_type=$FlowFixMeState 46 | 47 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\) 48 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)?:? #[0-9]+ 49 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError 50 | 51 | [lints] 52 | sketchy-null-number=warn 53 | sketchy-null-mixed=warn 54 | sketchy-number=warn 55 | untyped-type-import=warn 56 | nonstrict-import=warn 57 | deprecated-type=warn 58 | unsafe-getters-setters=warn 59 | unnecessary-invariant=warn 60 | signature-verification-failure=warn 61 | deprecated-utility=error 62 | 63 | [strict] 64 | deprecated-type 65 | nonstrict-import 66 | sketchy-null 67 | unclear-type 68 | unsafe-getters-setters 69 | untyped-import 70 | untyped-type-import 71 | 72 | [version] 73 | ^0.122.0 74 | -------------------------------------------------------------------------------- /example/.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | 24 | # Windows 25 | # 26 | *.binlog 27 | 28 | # yarn 29 | # 30 | yarn-error.log 31 | yarn.lock 32 | 33 | # Android/IntelliJ 34 | # 35 | build/ 36 | .idea 37 | .gradle 38 | local.properties 39 | *.iml 40 | 41 | # node.js 42 | # 43 | node_modules/ 44 | npm-debug.log 45 | yarn-error.log 46 | 47 | # BUCK 48 | buck-out/ 49 | \.buckd/ 50 | *.keystore 51 | !debug.keystore 52 | 53 | # fastlane 54 | # 55 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 56 | # screenshots whenever they are needed. 57 | # For more information about the recommended setup visit: 58 | # https://docs.fastlane.tools/best-practices/source-control/ 59 | 60 | */fastlane/report.xml 61 | */fastlane/Preview.html 62 | */fastlane/screenshots 63 | 64 | # Bundle artifact 65 | *.jsbundle 66 | 67 | # CocoaPods 68 | /ios/Pods/ 69 | -------------------------------------------------------------------------------- /example/.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | bracketSpacing: false, 3 | jsxBracketSameLine: true, 4 | singleQuote: true, 5 | trailingComma: 'all', 6 | }; 7 | -------------------------------------------------------------------------------- /example/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /example/App.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample React Native App 3 | * 4 | * adapted from App.js generated by the following command: 5 | * 6 | * react-native init example 7 | * 8 | * https://github.com/facebook/react-native 9 | */ 10 | 11 | import React, {Component, useEffect, useState} from 'react'; 12 | import { 13 | Platform, 14 | Pressable, 15 | ScrollView, 16 | StyleSheet, 17 | Text, 18 | TouchableOpacity, 19 | View, 20 | } from 'react-native'; 21 | import Orientation, { 22 | useOrientationChange, 23 | useDeviceOrientationChange, 24 | useLockListener, 25 | } from 'react-native-orientation-locker'; 26 | 27 | export default function App() { 28 | const [isLocked, setLocked] = useState(); 29 | const [orientation, setOrientation] = useState(); 30 | const [deviceOrientation, setDeviceOrientation] = useState(); 31 | const [lock, setLock] = useState(); 32 | 33 | // eslint-disable-next-line react-hooks/exhaustive-deps 34 | useEffect(() => { 35 | checkLocked(); 36 | }); 37 | 38 | useOrientationChange((o) => { 39 | setOrientation(o); 40 | }); 41 | 42 | useDeviceOrientationChange((o) => { 43 | setDeviceOrientation(o); 44 | }); 45 | 46 | useLockListener((o) => { 47 | setLocked(o); 48 | }); 49 | 50 | function checkLocked() { 51 | const locked = Orientation.isLocked(); 52 | if (locked !== isLocked) { 53 | setLocked(locked); 54 | } 55 | } 56 | 57 | return ( 58 | 59 | ☆OrientationLocker example☆ 60 | 61 | isLocked 62 | {isLocked ? 'TRUE' : 'FALSE'} 63 | 64 | 65 | addOrientationListener 66 | {orientation} 67 | 68 | 69 | addDeviceOrientationListener 70 | {deviceOrientation} 71 | 72 | 78 | { 81 | Orientation.lockToPortrait(); 82 | checkLocked(); 83 | }} 84 | style={styles.button}> 85 | Lock me to PORTRAIT 86 | 87 | { 90 | Orientation.lockToPortraitUpsideDown(); 91 | checkLocked(); 92 | }} 93 | style={styles.button}> 94 | Lock me to PORTRAIT UPSIDE DOWN 95 | 96 | { 99 | Orientation.lockToLandscape(); 100 | checkLocked(); 101 | }} 102 | style={styles.button}> 103 | Lock me to LANDSCAPE 104 | 105 | { 108 | Orientation.lockToLandscapeLeft(); 109 | checkLocked(); 110 | }} 111 | style={styles.button}> 112 | Lock me to LANDSCAPE LEFT 113 | 114 | { 117 | Orientation.lockToLandscapeRight(); 118 | checkLocked(); 119 | }} 120 | style={styles.button}> 121 | Lock me to LANDSCAPE RIGHT 122 | 123 | 124 | { 127 | Orientation.unlockAllOrientations(); 128 | checkLocked(); 129 | }} 130 | style={styles.button}> 131 | Unlock all orientations 132 | 133 | 134 | 135 | ); 136 | } 137 | 138 | const styles = StyleSheet.create({ 139 | container: { 140 | flex: 1, 141 | backgroundColor: '#F5FCFF', 142 | }, 143 | welcome: { 144 | fontSize: 20, 145 | textAlign: 'center', 146 | margin: 10, 147 | marginTop: 50, 148 | }, 149 | row: { 150 | flexDirection: 'row', 151 | marginTop: 10, 152 | paddingHorizontal: 15, 153 | alignItems: 'center', 154 | }, 155 | value: { 156 | backgroundColor: 'green', 157 | color: 'black', 158 | paddingHorizontal: 10, 159 | paddingVertical: 5, 160 | }, 161 | button: { 162 | backgroundColor: 'orange', 163 | padding: 10, 164 | borderRadius: 10, 165 | marginTop: 10, 166 | }, 167 | }); 168 | -------------------------------------------------------------------------------- /example/__tests__/App-test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @format 3 | */ 4 | 5 | import 'react-native'; 6 | import React from 'react'; 7 | import App from '../App'; 8 | 9 | // Note: test renderer must be required after react-native. 10 | import renderer from 'react-test-renderer'; 11 | 12 | it('renders correctly', () => { 13 | renderer.create(); 14 | }); 15 | -------------------------------------------------------------------------------- /example/android/app/BUCK: -------------------------------------------------------------------------------- 1 | # To learn about Buck see [Docs](https://buckbuild.com/). 2 | # To run your application with Buck: 3 | # - install Buck 4 | # - `npm start` - to start the packager 5 | # - `cd android` 6 | # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"` 7 | # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck 8 | # - `buck install -r android/app` - compile, install and run application 9 | # 10 | 11 | load(":build_defs.bzl", "create_aar_targets", "create_jar_targets") 12 | 13 | lib_deps = [] 14 | 15 | create_aar_targets(glob(["libs/*.aar"])) 16 | 17 | create_jar_targets(glob(["libs/*.jar"])) 18 | 19 | android_library( 20 | name = "all-libs", 21 | exported_deps = lib_deps, 22 | ) 23 | 24 | android_library( 25 | name = "app-code", 26 | srcs = glob([ 27 | "src/main/java/**/*.java", 28 | ]), 29 | deps = [ 30 | ":all-libs", 31 | ":build_config", 32 | ":res", 33 | ], 34 | ) 35 | 36 | android_build_config( 37 | name = "build_config", 38 | package = "com.example", 39 | ) 40 | 41 | android_resource( 42 | name = "res", 43 | package = "com.example", 44 | res = "src/main/res", 45 | ) 46 | 47 | android_binary( 48 | name = "app", 49 | keystore = "//android/keystores:debug", 50 | manifest = "src/main/AndroidManifest.xml", 51 | package_type = "debug", 52 | deps = [ 53 | ":app-code", 54 | ], 55 | ) 56 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | 3 | import com.android.build.OutputFile 4 | 5 | /** 6 | * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets 7 | * and bundleReleaseJsAndAssets). 8 | * These basically call `react-native bundle` with the correct arguments during the Android build 9 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the 10 | * bundle directly from the development server. Below you can see all the possible configurations 11 | * and their defaults. If you decide to add a configuration block, make sure to add it before the 12 | * `apply from: "../../node_modules/react-native/react.gradle"` line. 13 | * 14 | * project.ext.react = [ 15 | * // the name of the generated asset file containing your JS bundle 16 | * bundleAssetName: "index.android.bundle", 17 | * 18 | * // the entry file for bundle generation. If none specified and 19 | * // "index.android.js" exists, it will be used. Otherwise "index.js" is 20 | * // default. Can be overridden with ENTRY_FILE environment variable. 21 | * entryFile: "index.android.js", 22 | * 23 | * // https://reactnative.dev/docs/performance#enable-the-ram-format 24 | * bundleCommand: "ram-bundle", 25 | * 26 | * // whether to bundle JS and assets in debug mode 27 | * bundleInDebug: false, 28 | * 29 | * // whether to bundle JS and assets in release mode 30 | * bundleInRelease: true, 31 | * 32 | * // whether to bundle JS and assets in another build variant (if configured). 33 | * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants 34 | * // The configuration property can be in the following formats 35 | * // 'bundleIn${productFlavor}${buildType}' 36 | * // 'bundleIn${buildType}' 37 | * // bundleInFreeDebug: true, 38 | * // bundleInPaidRelease: true, 39 | * // bundleInBeta: true, 40 | * 41 | * // whether to disable dev mode in custom build variants (by default only disabled in release) 42 | * // for example: to disable dev mode in the staging build type (if configured) 43 | * devDisabledInStaging: true, 44 | * // The configuration property can be in the following formats 45 | * // 'devDisabledIn${productFlavor}${buildType}' 46 | * // 'devDisabledIn${buildType}' 47 | * 48 | * // the root of your project, i.e. where "package.json" lives 49 | * root: "../../", 50 | * 51 | * // where to put the JS bundle asset in debug mode 52 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", 53 | * 54 | * // where to put the JS bundle asset in release mode 55 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release", 56 | * 57 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 58 | * // require('./image.png')), in debug mode 59 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", 60 | * 61 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 62 | * // require('./image.png')), in release mode 63 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", 64 | * 65 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means 66 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to 67 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle 68 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ 69 | * // for example, you might want to remove it from here. 70 | * inputExcludes: ["android/**", "ios/**"], 71 | * 72 | * // override which node gets called and with what additional arguments 73 | * nodeExecutableAndArgs: ["node"], 74 | * 75 | * // supply additional arguments to the packager 76 | * extraPackagerArgs: [] 77 | * ] 78 | */ 79 | 80 | project.ext.react = [ 81 | enableHermes: false, // clean and rebuild if changing 82 | ] 83 | 84 | apply from: "../../node_modules/react-native/react.gradle" 85 | 86 | /** 87 | * Set this to true to create two separate APKs instead of one: 88 | * - An APK that only works on ARM devices 89 | * - An APK that only works on x86 devices 90 | * The advantage is the size of the APK is reduced by about 4MB. 91 | * Upload all the APKs to the Play Store and people will download 92 | * the correct one based on the CPU architecture of their device. 93 | */ 94 | def enableSeparateBuildPerCPUArchitecture = false 95 | 96 | /** 97 | * Run Proguard to shrink the Java bytecode in release builds. 98 | */ 99 | def enableProguardInReleaseBuilds = false 100 | 101 | /** 102 | * The preferred build flavor of JavaScriptCore. 103 | * 104 | * For example, to use the international variant, you can use: 105 | * `def jscFlavor = 'org.webkit:android-jsc-intl:+'` 106 | * 107 | * The international variant includes ICU i18n library and necessary data 108 | * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that 109 | * give correct results when using with locales other than en-US. Note that 110 | * this variant is about 6MiB larger per architecture than default. 111 | */ 112 | def jscFlavor = 'org.webkit:android-jsc:+' 113 | 114 | /** 115 | * Whether to enable the Hermes VM. 116 | * 117 | * This should be set on project.ext.react and mirrored here. If it is not set 118 | * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode 119 | * and the benefits of using Hermes will therefore be sharply reduced. 120 | */ 121 | def enableHermes = project.ext.react.get("enableHermes", false); 122 | 123 | android { 124 | compileSdkVersion rootProject.ext.compileSdkVersion 125 | 126 | compileOptions { 127 | sourceCompatibility JavaVersion.VERSION_1_8 128 | targetCompatibility JavaVersion.VERSION_1_8 129 | } 130 | 131 | defaultConfig { 132 | applicationId "com.example" 133 | minSdkVersion rootProject.ext.minSdkVersion 134 | targetSdkVersion rootProject.ext.targetSdkVersion 135 | versionCode 1 136 | versionName "1.0" 137 | } 138 | splits { 139 | abi { 140 | reset() 141 | enable enableSeparateBuildPerCPUArchitecture 142 | universalApk false // If true, also generate a universal APK 143 | include "armeabi-v7a", "x86", "arm64-v8a", "x86_64" 144 | } 145 | } 146 | signingConfigs { 147 | debug { 148 | storeFile file('debug.keystore') 149 | storePassword 'android' 150 | keyAlias 'androiddebugkey' 151 | keyPassword 'android' 152 | } 153 | } 154 | buildTypes { 155 | debug { 156 | signingConfig signingConfigs.debug 157 | } 158 | release { 159 | // Caution! In production, you need to generate your own keystore file. 160 | // see https://reactnative.dev/docs/signed-apk-android. 161 | signingConfig signingConfigs.debug 162 | minifyEnabled enableProguardInReleaseBuilds 163 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 164 | } 165 | } 166 | 167 | // applicationVariants are e.g. debug, release 168 | applicationVariants.all { variant -> 169 | variant.outputs.each { output -> 170 | // For each separate APK per architecture, set a unique version code as described here: 171 | // https://developer.android.com/studio/build/configure-apk-splits.html 172 | def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4] 173 | def abi = output.getFilter(OutputFile.ABI) 174 | if (abi != null) { // null for the universal-debug, universal-release variants 175 | output.versionCodeOverride = 176 | versionCodes.get(abi) * 1048576 + defaultConfig.versionCode 177 | } 178 | 179 | } 180 | } 181 | } 182 | 183 | dependencies { 184 | implementation fileTree(dir: "libs", include: ["*.jar"]) 185 | //noinspection GradleDynamicVersion 186 | implementation "com.facebook.react:react-native:+" // From node_modules 187 | 188 | implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" 189 | 190 | debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") { 191 | exclude group:'com.facebook.fbjni' 192 | } 193 | 194 | debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { 195 | exclude group:'com.facebook.flipper' 196 | exclude group:'com.squareup.okhttp3', module:'okhttp' 197 | } 198 | 199 | debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") { 200 | exclude group:'com.facebook.flipper' 201 | } 202 | 203 | if (enableHermes) { 204 | def hermesPath = "../../node_modules/hermes-engine/android/"; 205 | debugImplementation files(hermesPath + "hermes-debug.aar") 206 | releaseImplementation files(hermesPath + "hermes-release.aar") 207 | } else { 208 | implementation jscFlavor 209 | } 210 | } 211 | 212 | // Run this once to be able to run the application with BUCK 213 | // puts all compile dependencies into folder libs for BUCK to use 214 | task copyDownloadableDepsToLibs(type: Copy) { 215 | from configurations.compile 216 | into 'libs' 217 | } 218 | 219 | apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) 220 | -------------------------------------------------------------------------------- /example/android/app/build_defs.bzl: -------------------------------------------------------------------------------- 1 | """Helper definitions to glob .aar and .jar targets""" 2 | 3 | def create_aar_targets(aarfiles): 4 | for aarfile in aarfiles: 5 | name = "aars__" + aarfile[aarfile.rindex("/") + 1:aarfile.rindex(".aar")] 6 | lib_deps.append(":" + name) 7 | android_prebuilt_aar( 8 | name = name, 9 | aar = aarfile, 10 | ) 11 | 12 | def create_jar_targets(jarfiles): 13 | for jarfile in jarfiles: 14 | name = "jars__" + jarfile[jarfile.rindex("/") + 1:jarfile.rindex(".jar")] 15 | lib_deps.append(":" + name) 16 | prebuilt_jar( 17 | name = name, 18 | binary_jar = jarfile, 19 | ) 20 | -------------------------------------------------------------------------------- /example/android/app/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonday/react-native-orientation-locker/d67716620199137b7b53df835b735625039f92e6/example/android/app/debug.keystore -------------------------------------------------------------------------------- /example/android/app/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonday/react-native-orientation-locker/d67716620199137b7b53df835b735625039f92e6/example/android/app/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/android/app/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Nov 17 17:37:11 PST 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip 7 | -------------------------------------------------------------------------------- /example/android/app/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /example/android/app/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/android/app/src/debug/java/com/example/ReactNativeFlipper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | *

This source code is licensed under the MIT license found in the LICENSE file in the root 5 | * directory of this source tree. 6 | */ 7 | package com.example; 8 | 9 | import android.content.Context; 10 | import com.facebook.flipper.android.AndroidFlipperClient; 11 | import com.facebook.flipper.android.utils.FlipperUtils; 12 | import com.facebook.flipper.core.FlipperClient; 13 | import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin; 14 | import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin; 15 | import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin; 16 | import com.facebook.flipper.plugins.inspector.DescriptorMapping; 17 | import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin; 18 | import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor; 19 | import com.facebook.flipper.plugins.network.NetworkFlipperPlugin; 20 | import com.facebook.flipper.plugins.react.ReactFlipperPlugin; 21 | import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin; 22 | import com.facebook.react.ReactInstanceManager; 23 | import com.facebook.react.bridge.ReactContext; 24 | import com.facebook.react.modules.network.NetworkingModule; 25 | import okhttp3.OkHttpClient; 26 | 27 | public class ReactNativeFlipper { 28 | public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { 29 | if (FlipperUtils.shouldEnableFlipper(context)) { 30 | final FlipperClient client = AndroidFlipperClient.getInstance(context); 31 | 32 | client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults())); 33 | client.addPlugin(new ReactFlipperPlugin()); 34 | client.addPlugin(new DatabasesFlipperPlugin(context)); 35 | client.addPlugin(new SharedPreferencesFlipperPlugin(context)); 36 | client.addPlugin(CrashReporterPlugin.getInstance()); 37 | 38 | NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin(); 39 | NetworkingModule.setCustomClientBuilder( 40 | new NetworkingModule.CustomClientBuilder() { 41 | @Override 42 | public void apply(OkHttpClient.Builder builder) { 43 | builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin)); 44 | } 45 | }); 46 | client.addPlugin(networkFlipperPlugin); 47 | client.start(); 48 | 49 | // Fresco Plugin needs to ensure that ImagePipelineFactory is initialized 50 | // Hence we run if after all native modules have been initialized 51 | ReactContext reactContext = reactInstanceManager.getCurrentReactContext(); 52 | if (reactContext == null) { 53 | reactInstanceManager.addReactInstanceEventListener( 54 | new ReactInstanceManager.ReactInstanceEventListener() { 55 | @Override 56 | public void onReactContextInitialized(ReactContext reactContext) { 57 | reactInstanceManager.removeReactInstanceEventListener(this); 58 | reactContext.runOnNativeModulesQueueThread( 59 | new Runnable() { 60 | @Override 61 | public void run() { 62 | client.addPlugin(new FrescoFlipperPlugin()); 63 | } 64 | }); 65 | } 66 | }); 67 | } else { 68 | client.addPlugin(new FrescoFlipperPlugin()); 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 13 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/example/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import com.facebook.react.ReactActivity; 4 | 5 | import android.content.Intent; 6 | import android.content.res.Configuration; 7 | 8 | public class MainActivity extends ReactActivity { 9 | 10 | /** 11 | * Returns the name of the main component registered from JavaScript. This is used to schedule 12 | * rendering of the component. 13 | */ 14 | @Override 15 | protected String getMainComponentName() { 16 | return "example"; 17 | } 18 | 19 | @Override 20 | public void onConfigurationChanged(Configuration newConfig) { 21 | super.onConfigurationChanged(newConfig); 22 | Intent intent = new Intent("onConfigurationChanged"); 23 | intent.putExtra("newConfig", newConfig); 24 | this.sendBroadcast(intent); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/example/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import com.facebook.react.PackageList; 6 | import com.facebook.react.ReactApplication; 7 | import com.facebook.react.ReactInstanceManager; 8 | import com.facebook.react.ReactNativeHost; 9 | import com.facebook.react.ReactPackage; 10 | import com.facebook.soloader.SoLoader; 11 | import java.lang.reflect.InvocationTargetException; 12 | import java.util.List; 13 | 14 | import org.wonday.orientation.OrientationActivityLifecycle; 15 | 16 | public class MainApplication extends Application implements ReactApplication { 17 | 18 | private final ReactNativeHost mReactNativeHost = 19 | new ReactNativeHost(this) { 20 | @Override 21 | public boolean getUseDeveloperSupport() { 22 | return BuildConfig.DEBUG; 23 | } 24 | 25 | @Override 26 | protected List getPackages() { 27 | @SuppressWarnings("UnnecessaryLocalVariable") 28 | List packages = new PackageList(this).getPackages(); 29 | // Packages that cannot be autolinked yet can be added manually here, for example: 30 | // packages.add(new MyReactNativePackage()); 31 | return packages; 32 | } 33 | 34 | @Override 35 | protected String getJSMainModuleName() { 36 | return "index"; 37 | } 38 | }; 39 | 40 | @Override 41 | public ReactNativeHost getReactNativeHost() { 42 | return mReactNativeHost; 43 | } 44 | 45 | @Override 46 | public void onCreate() { 47 | super.onCreate(); 48 | SoLoader.init(this, /* native exopackage */ false); 49 | initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); 50 | 51 | registerActivityLifecycleCallbacks(OrientationActivityLifecycle.getInstance()); 52 | } 53 | 54 | /** 55 | * Loads Flipper in React Native templates. Call this in the onCreate method with something like 56 | * initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); 57 | * 58 | * @param context 59 | * @param reactInstanceManager 60 | */ 61 | private static void initializeFlipper( 62 | Context context, ReactInstanceManager reactInstanceManager) { 63 | if (BuildConfig.DEBUG) { 64 | try { 65 | /* 66 | We use reflection here to pick up the class that initializes Flipper, 67 | since Flipper library is not available in release mode 68 | */ 69 | Class aClass = Class.forName("com.example.ReactNativeFlipper"); 70 | aClass 71 | .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class) 72 | .invoke(null, context, reactInstanceManager); 73 | } catch (ClassNotFoundException e) { 74 | e.printStackTrace(); 75 | } catch (NoSuchMethodException e) { 76 | e.printStackTrace(); 77 | } catch (IllegalAccessException e) { 78 | e.printStackTrace(); 79 | } catch (InvocationTargetException e) { 80 | e.printStackTrace(); 81 | } 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonday/react-native-orientation-locker/d67716620199137b7b53df835b735625039f92e6/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonday/react-native-orientation-locker/d67716620199137b7b53df835b735625039f92e6/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonday/react-native-orientation-locker/d67716620199137b7b53df835b735625039f92e6/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonday/react-native-orientation-locker/d67716620199137b7b53df835b735625039f92e6/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonday/react-native-orientation-locker/d67716620199137b7b53df835b735625039f92e6/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonday/react-native-orientation-locker/d67716620199137b7b53df835b735625039f92e6/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonday/react-native-orientation-locker/d67716620199137b7b53df835b735625039f92e6/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonday/react-native-orientation-locker/d67716620199137b7b53df835b735625039f92e6/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonday/react-native-orientation-locker/d67716620199137b7b53df835b735625039f92e6/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonday/react-native-orientation-locker/d67716620199137b7b53df835b735625039f92e6/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | example 3 | 4 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext { 5 | buildToolsVersion = "29.0.2" 6 | minSdkVersion = 16 7 | compileSdkVersion = 29 8 | targetSdkVersion = 29 9 | } 10 | repositories { 11 | google() 12 | jcenter() 13 | } 14 | dependencies { 15 | classpath("com.android.tools.build:gradle:3.5.3") 16 | // NOTE: Do not place your application dependencies here; they belong 17 | // in the individual module build.gradle files 18 | } 19 | } 20 | 21 | allprojects { 22 | repositories { 23 | mavenLocal() 24 | maven { 25 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 26 | url("$rootDir/../node_modules/react-native/android") 27 | } 28 | maven { 29 | // Android JSC is installed from npm 30 | url("$rootDir/../node_modules/jsc-android/dist") 31 | } 32 | 33 | google() 34 | jcenter() 35 | maven { url 'https://www.jitpack.io' } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | # AndroidX package structure to make it clearer which packages are bundled with the 21 | # Android operating system, and which are packaged with your app's APK 22 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 23 | android.useAndroidX=true 24 | # Automatically convert third-party libraries to use AndroidX 25 | android.enableJetifier=true 26 | 27 | # Version of flipper SDK to use with React Native 28 | FLIPPER_VERSION=0.37.0 29 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonday/react-native-orientation-locker/d67716620199137b7b53df835b735625039f92e6/example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /example/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin or MSYS, switch paths to Windows format before running java 129 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=`expr $i + 1` 158 | done 159 | case $i in 160 | 0) set -- ;; 161 | 1) set -- "$args0" ;; 162 | 2) set -- "$args0" "$args1" ;; 163 | 3) set -- "$args0" "$args1" "$args2" ;; 164 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=`save "$@"` 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 182 | 183 | exec "$JAVACMD" "$@" 184 | -------------------------------------------------------------------------------- /example/android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto init 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto init 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :init 68 | @rem Get command-line arguments, handling Windows variants 69 | 70 | if not "%OS%" == "Windows_NT" goto win9xME_args 71 | 72 | :win9xME_args 73 | @rem Slurp the command line arguments. 74 | set CMD_LINE_ARGS= 75 | set _SKIP=2 76 | 77 | :win9xME_args_slurp 78 | if "x%~1" == "x" goto execute 79 | 80 | set CMD_LINE_ARGS=%* 81 | 82 | :execute 83 | @rem Setup the command line 84 | 85 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 86 | 87 | @rem Execute Gradle 88 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 89 | 90 | :end 91 | @rem End local scope for the variables with windows NT shell 92 | if "%ERRORLEVEL%"=="0" goto mainEnd 93 | 94 | :fail 95 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 96 | rem the _cmd.exe /c_ return code! 97 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 98 | exit /b 1 99 | 100 | :mainEnd 101 | if "%OS%"=="Windows_NT" endlocal 102 | 103 | :omega 104 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'example' 2 | apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) 3 | include ':app' 4 | -------------------------------------------------------------------------------- /example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "displayName": "example" 4 | } -------------------------------------------------------------------------------- /example/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:metro-react-native-babel-preset'], 3 | }; 4 | -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @format 3 | */ 4 | 5 | import {AppRegistry} from 'react-native'; 6 | import App from './App'; 7 | import {name as appName} from './app.json'; 8 | 9 | AppRegistry.registerComponent(appName, () => App); 10 | -------------------------------------------------------------------------------- /example/ios/Podfile: -------------------------------------------------------------------------------- 1 | require_relative '../node_modules/react-native/scripts/react_native_pods' 2 | require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' 3 | 4 | platform :ios, '10.0' 5 | 6 | target 'example' do 7 | config = use_native_modules! 8 | 9 | use_react_native!(:path => config["reactNativePath"]) 10 | 11 | target 'exampleTests' do 12 | inherit! :complete 13 | # Pods for testing 14 | end 15 | 16 | # Enables Flipper. 17 | # 18 | # Note that if you have use_frameworks! enabled, Flipper will not work and 19 | # you should disable these next few lines. 20 | use_flipper! 21 | post_install do |installer| 22 | flipper_post_install(installer) 23 | end 24 | end 25 | 26 | target 'example-tvOS' do 27 | # Pods for example-tvOS 28 | 29 | target 'example-tvOSTests' do 30 | inherit! :search_paths 31 | # Pods for testing 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /example/ios/example-tvOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | NSAppTransportSecurity 26 | 27 | NSExceptionDomains 28 | 29 | localhost 30 | 31 | NSExceptionAllowsInsecureHTTPLoads 32 | 33 | 34 | 35 | 36 | NSLocationWhenInUseUsageDescription 37 | 38 | UILaunchStoryboardName 39 | LaunchScreen 40 | UIRequiredDeviceCapabilities 41 | 42 | armv7 43 | 44 | UISupportedInterfaceOrientations 45 | 46 | UIInterfaceOrientationPortrait 47 | UIInterfaceOrientationLandscapeLeft 48 | UIInterfaceOrientationLandscapeRight 49 | 50 | UIViewControllerBasedStatusBarAppearance 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /example/ios/example-tvOSTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /example/ios/example/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface AppDelegate : UIResponder 5 | 6 | @property (nonatomic, strong) UIWindow *window; 7 | 8 | @end 9 | -------------------------------------------------------------------------------- /example/ios/example/AppDelegate.m: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | 3 | #import 4 | #import 5 | #import 6 | #import "Orientation.h" 7 | 8 | #ifdef FB_SONARKIT_ENABLED 9 | #import 10 | #import 11 | #import 12 | #import 13 | #import 14 | #import 15 | 16 | static void InitializeFlipper(UIApplication *application) { 17 | FlipperClient *client = [FlipperClient sharedClient]; 18 | SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults]; 19 | [client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]]; 20 | [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]]; 21 | [client addPlugin:[FlipperKitReactPlugin new]]; 22 | [client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]]; 23 | [client start]; 24 | } 25 | #endif 26 | 27 | @implementation AppDelegate 28 | 29 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 30 | { 31 | #ifdef FB_SONARKIT_ENABLED 32 | InitializeFlipper(application); 33 | #endif 34 | 35 | RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; 36 | RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge 37 | moduleName:@"example" 38 | initialProperties:nil]; 39 | 40 | rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; 41 | 42 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 43 | UIViewController *rootViewController = [UIViewController new]; 44 | rootViewController.view = rootView; 45 | self.window.rootViewController = rootViewController; 46 | [self.window makeKeyAndVisible]; 47 | return YES; 48 | } 49 | 50 | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge 51 | { 52 | #if DEBUG 53 | return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; 54 | #else 55 | return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; 56 | #endif 57 | } 58 | 59 | - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { 60 | return [Orientation getOrientation]; 61 | } 62 | @end 63 | -------------------------------------------------------------------------------- /example/ios/example/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /example/ios/example/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /example/ios/example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | example 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSRequiresIPhoneOS 26 | 27 | NSAppTransportSecurity 28 | 29 | NSAllowsArbitraryLoads 30 | 31 | NSExceptionDomains 32 | 33 | localhost 34 | 35 | NSExceptionAllowsInsecureHTTPLoads 36 | 37 | 38 | 39 | 40 | NSLocationWhenInUseUsageDescription 41 | 42 | UILaunchStoryboardName 43 | LaunchScreen 44 | UIRequiredDeviceCapabilities 45 | 46 | armv7 47 | 48 | UISupportedInterfaceOrientations 49 | 50 | UIInterfaceOrientationPortrait 51 | UIInterfaceOrientationLandscapeLeft 52 | UIInterfaceOrientationLandscapeRight 53 | UIInterfaceOrientationPortraitUpsideDown 54 | 55 | UIViewControllerBasedStatusBarAppearance 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /example/ios/example/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 25 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /example/ios/example/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #import "AppDelegate.h" 4 | 5 | int main(int argc, char * argv[]) { 6 | @autoreleasepool { 7 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/ios/exampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /example/ios/exampleTests/exampleTests.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | #import 5 | #import 6 | 7 | #define TIMEOUT_SECONDS 600 8 | #define TEXT_TO_LOOK_FOR @"Welcome to React" 9 | 10 | @interface exampleTests : XCTestCase 11 | 12 | @end 13 | 14 | @implementation exampleTests 15 | 16 | - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test 17 | { 18 | if (test(view)) { 19 | return YES; 20 | } 21 | for (UIView *subview in [view subviews]) { 22 | if ([self findSubviewInView:subview matching:test]) { 23 | return YES; 24 | } 25 | } 26 | return NO; 27 | } 28 | 29 | - (void)testRendersWelcomeScreen 30 | { 31 | UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController]; 32 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; 33 | BOOL foundElement = NO; 34 | 35 | __block NSString *redboxError = nil; 36 | #ifdef DEBUG 37 | RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) { 38 | if (level >= RCTLogLevelError) { 39 | redboxError = message; 40 | } 41 | }); 42 | #endif 43 | 44 | while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) { 45 | [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 46 | [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 47 | 48 | foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) { 49 | if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) { 50 | return YES; 51 | } 52 | return NO; 53 | }]; 54 | } 55 | 56 | #ifdef DEBUG 57 | RCTSetLogFunction(RCTDefaultLogFunction); 58 | #endif 59 | 60 | XCTAssertNil(redboxError, @"RedBox error: %@", redboxError); 61 | XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS); 62 | } 63 | 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /example/metro.config.js: -------------------------------------------------------------------------------- 1 | // metro.config.js 2 | // 3 | // with multiple workarounds for this issue with symlinks: 4 | // https://github.com/facebook/metro/issues/1 5 | // 6 | // with thanks to @johnryan () 7 | // for the pointers to multiple workaround solutions here: 8 | // https://github.com/facebook/metro/issues/1#issuecomment-541642857 9 | // 10 | // see also this discussion: 11 | // https://github.com/brodybits/create-react-native-module/issues/232 12 | 13 | const path = require('path'); 14 | const blacklist = require('metro-config/src/defaults/blacklist'); 15 | 16 | module.exports = { 17 | // workaround for an issue with symlinks encountered starting with 18 | // metro@0.55 / React Native 0.61 19 | // (not needed with React Native 0.60 / metro@0.54) 20 | resolver: { 21 | extraNodeModules: new Proxy( 22 | {}, 23 | { get: (_, name) => path.resolve('.', 'node_modules', name) } 24 | ), 25 | blacklistRE: blacklist([/..\/node_modules\/.*/]), 26 | }, 27 | 28 | // quick workaround for another issue with symlinks 29 | watchFolders: ['.', '..'] 30 | } 31 | -------------------------------------------------------------------------------- /example/metro.config.windows.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Metro configuration for React Native 3 | * https://github.com/facebook/react-native 4 | * 5 | * @format 6 | */ 7 | const fs = require('fs'); 8 | const path = require('path'); 9 | const blacklist = require('metro-config/src/defaults/blacklist'); 10 | 11 | const rnPath = fs.realpathSync( 12 | path.resolve(require.resolve('react-native/package.json'), '..'), 13 | ); 14 | const rnwPath = fs.realpathSync( 15 | path.resolve(require.resolve('react-native-windows/package.json'), '..'), 16 | ); 17 | 18 | module.exports = { 19 | resolver: { 20 | extraNodeModules: { 21 | // Redirect react-native to react-native-windows 22 | 'react-native': rnwPath, 23 | 'react-native-windows': rnwPath, 24 | }, 25 | // Include the macos platform in addition to the defaults because the fork includes macos, but doesn't declare it 26 | platforms: ['ios', 'android', 'windesktop', 'windows', 'web', 'macos'], 27 | // Since there are multiple copies of react-native, we need to ensure that metro only sees one of them 28 | // This should go in RN 0.61 when haste is removed 29 | blacklistRE: blacklist([ 30 | new RegExp( 31 | `${(path.resolve(rnPath) + path.sep).replace(/[/\\]/g, '/')}.*`, 32 | ), 33 | 34 | // This stops "react-native run-windows" from causing the metro server to crash if its already running 35 | new RegExp( 36 | `${path.resolve(__dirname, 'windows').replace(/[/\\]/g, '/')}.*`, 37 | ), 38 | // Avoid error EBUSY: resource busy or locked, open '...\vnext\msbuild.ProjectImports.zip' when building 'vnext\Microsoft.ReactNative.sln' with '/bl' 39 | /.*\.ProjectImports\.zip/, 40 | ]), 41 | }, 42 | transformer: { 43 | getTransformOptions: async () => ({ 44 | transform: { 45 | experimentalImportSupport: false, 46 | inlineRequires: false, 47 | }, 48 | }), 49 | }, 50 | }; 51 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "android": "react-native run-android", 7 | "ios": "react-native run-ios", 8 | "start": "react-native start", 9 | "test": "jest", 10 | "lint": "eslint .", 11 | "clean:windows": "rmdir /s node_modules\\react-native-orientation-locker\\node_modules\\", 12 | "start:windows": "react-native start --use-react-native-windows", 13 | "windows": "react-native run-windows --no-packager" 14 | }, 15 | "dependencies": { 16 | "react": "16.13.1", 17 | "react-native": "0.63.2", 18 | "react-native-orientation-locker": "file: ../../../", 19 | "react-native-windows": "^0.63.3" 20 | }, 21 | "devDependencies": { 22 | "@babel/core": "^7.11.6", 23 | "@babel/runtime": "^7.11.2", 24 | "@react-native-community/eslint-config": "^2.0.0", 25 | "babel-jest": "^26.3.0", 26 | "eslint": "^7.8.1", 27 | "jest": "^26.4.2", 28 | "metro-react-native-babel-preset": "^0.63.0", 29 | "react-test-renderer": "16.13.1" 30 | }, 31 | "jest": { 32 | "preset": "react-native" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /example/react-native.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This cli config is needed for the coexistance of react-native and other 3 | * out-of-tree implementations such react-native-macos. 4 | * The following issue is tracked by 5 | * https://github.com/react-native-community/discussions-and-proposals/issues/182 6 | * 7 | * The work-around involves having a metro.config.js for each out-of-tree 8 | * platform, i.e. metro.config.js for react-native and 9 | * metro.config.macos.js for react-native-macos. 10 | * This react-native.config.js looks for a --use-react-native-macos 11 | * switch and when present pushes --config=metro.config.macos.js 12 | * and specifies reactNativePath: 'node_modules/react-native-macos'. 13 | * The metro.config.js has to blacklist 'node_modules/react-native-macos', 14 | * and conversely metro.config.macos.js has to blacklist 'node_modules/react-native'. 15 | */ 16 | 'use strict'; 17 | 18 | const path = require('path'); 19 | 20 | const windowsSwitch = '--use-react-native-windows'; 21 | if (process.argv.includes(windowsSwitch)) { 22 | process.argv = process.argv.filter(arg => arg !== windowsSwitch); 23 | process.argv.push('--config=metro.config.windows.js'); 24 | module.exports = { 25 | reactNativePath: 'node_modules/react-native-windows', 26 | }; 27 | } else { 28 | module.exports = { 29 | project: { 30 | android: {sourceDir: './android'}, 31 | ios: {project: './ios/example.xcodeproj'}, 32 | }, 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /example/windows/.gitignore: -------------------------------------------------------------------------------- 1 | *AppPackages* 2 | *BundleArtifacts* 3 | 4 | #OS junk files 5 | [Tt]humbs.db 6 | *.DS_Store 7 | 8 | #Visual Studio files 9 | *.[Oo]bj 10 | *.user 11 | *.aps 12 | *.pch 13 | *.vspscc 14 | *.vssscc 15 | *_i.c 16 | *_p.c 17 | *.ncb 18 | *.suo 19 | *.tlb 20 | *.tlh 21 | *.bak 22 | *.[Cc]ache 23 | *.ilk 24 | *.log 25 | *.lib 26 | *.sbr 27 | *.sdf 28 | *.opensdf 29 | *.opendb 30 | *.unsuccessfulbuild 31 | ipch/ 32 | [Oo]bj/ 33 | [Bb]in 34 | [Dd]ebug*/ 35 | [Rr]elease*/ 36 | Ankh.NoLoad 37 | 38 | # Visual C++ cache files 39 | ipch/ 40 | *.aps 41 | *.ncb 42 | *.opendb 43 | *.opensdf 44 | *.sdf 45 | *.cachefile 46 | *.VC.db 47 | *.VC.VC.opendb 48 | 49 | #MonoDevelop 50 | *.pidb 51 | *.userprefs 52 | 53 | #Tooling 54 | _ReSharper*/ 55 | *.resharper 56 | [Tt]est[Rr]esult* 57 | *.sass-cache 58 | 59 | #Project files 60 | [Bb]uild/ 61 | 62 | #Subversion files 63 | .svn 64 | 65 | # Office Temp Files 66 | ~$* 67 | 68 | # vim Temp Files 69 | *~ 70 | 71 | #NuGet 72 | packages/ 73 | *.nupkg 74 | 75 | #ncrunch 76 | *ncrunch* 77 | *crunch*.local.xml 78 | 79 | # visual studio database projects 80 | *.dbmdl 81 | 82 | #Test files 83 | *.testsettings 84 | 85 | #Other files 86 | *.DotSettings 87 | .vs/ 88 | *project.lock.json 89 | 90 | #Files generated by the VS build 91 | **/Generated Files/** 92 | 93 | -------------------------------------------------------------------------------- /example/windows/example/.gitignore: -------------------------------------------------------------------------------- 1 | /Bundle 2 | -------------------------------------------------------------------------------- /example/windows/example/App.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | 3 | #include "App.h" 4 | 5 | #include "AutolinkedNativeModules.g.h" 6 | #include "ReactPackageProvider.h" 7 | 8 | 9 | using namespace winrt::example; 10 | using namespace winrt::example::implementation; 11 | using namespace winrt; 12 | using namespace Windows::UI::Xaml; 13 | using namespace Windows::UI::Xaml::Controls; 14 | using namespace Windows::UI::Xaml::Navigation; 15 | using namespace Windows::ApplicationModel; 16 | 17 | ///

18 | /// Initializes the singleton application object. This is the first line of 19 | /// authored code executed, and as such is the logical equivalent of main() or 20 | /// WinMain(). 21 | /// 22 | App::App() noexcept 23 | { 24 | #if BUNDLE 25 | JavaScriptBundleFile(L"index.windows"); 26 | InstanceSettings().UseWebDebugger(false); 27 | InstanceSettings().UseFastRefresh(false); 28 | #else 29 | JavaScriptMainModuleName(L"index"); 30 | InstanceSettings().UseWebDebugger(true); 31 | InstanceSettings().UseFastRefresh(true); 32 | #endif 33 | 34 | #if _DEBUG 35 | InstanceSettings().UseDeveloperSupport(true); 36 | #else 37 | InstanceSettings().UseDeveloperSupport(false); 38 | #endif 39 | 40 | RegisterAutolinkedNativeModulePackages(PackageProviders()); // Includes any autolinked modules 41 | 42 | PackageProviders().Append(make()); // Includes all modules in this project 43 | PackageProviders().Append(winrt::OrientationWindows::ReactPackageProvider()); 44 | 45 | InitializeComponent(); 46 | } 47 | 48 | /// 49 | /// Invoked when the application is launched normally by the end user. Other entry points 50 | /// will be used such as when the application is launched to open a specific file. 51 | /// 52 | /// Details about the launch request and process. 53 | void App::OnLaunched(activation::LaunchActivatedEventArgs const& e) 54 | { 55 | super::OnLaunched(e); 56 | 57 | Frame rootFrame = Window::Current().Content().as(); 58 | rootFrame.Navigate(xaml_typename(), box_value(e.Arguments())); 59 | } 60 | 61 | /// 62 | /// Invoked when application execution is being suspended. Application state is saved 63 | /// without knowing whether the application will be terminated or resumed with the contents 64 | /// of memory still intact. 65 | /// 66 | /// The source of the suspend request. 67 | /// Details about the suspend request. 68 | void App::OnSuspending([[maybe_unused]] IInspectable const& sender, [[maybe_unused]] SuspendingEventArgs const& e) 69 | { 70 | // Save application state and stop any background activity 71 | } 72 | 73 | /// 74 | /// Invoked when Navigation to a certain page fails 75 | /// 76 | /// The Frame which failed navigation 77 | /// Details about the navigation failure 78 | void App::OnNavigationFailed(IInspectable const&, NavigationFailedEventArgs const& e) 79 | { 80 | throw hresult_error(E_FAIL, hstring(L"Failed to load Page ") + e.SourcePageType().Name); 81 | } 82 | -------------------------------------------------------------------------------- /example/windows/example/App.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "App.xaml.g.h" 4 | 5 | namespace activation = winrt::Windows::ApplicationModel::Activation; 6 | 7 | namespace winrt::example::implementation 8 | { 9 | struct App : AppT 10 | { 11 | App() noexcept; 12 | void OnLaunched(activation::LaunchActivatedEventArgs const&); 13 | void OnSuspending(IInspectable const&, Windows::ApplicationModel::SuspendingEventArgs const&); 14 | void OnNavigationFailed(IInspectable const&, Windows::UI::Xaml::Navigation::NavigationFailedEventArgs const&); 15 | private: 16 | using super = AppT; 17 | }; 18 | } // namespace winrt::example::implementation 19 | 20 | 21 | -------------------------------------------------------------------------------- /example/windows/example/App.idl: -------------------------------------------------------------------------------- 1 | namespace example 2 | { 3 | } 4 | -------------------------------------------------------------------------------- /example/windows/example/App.xaml: -------------------------------------------------------------------------------- 1 |  7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/windows/example/Assets/LockScreenLogo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonday/react-native-orientation-locker/d67716620199137b7b53df835b735625039f92e6/example/windows/example/Assets/LockScreenLogo.scale-200.png -------------------------------------------------------------------------------- /example/windows/example/Assets/SplashScreen.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonday/react-native-orientation-locker/d67716620199137b7b53df835b735625039f92e6/example/windows/example/Assets/SplashScreen.scale-200.png -------------------------------------------------------------------------------- /example/windows/example/Assets/Square150x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonday/react-native-orientation-locker/d67716620199137b7b53df835b735625039f92e6/example/windows/example/Assets/Square150x150Logo.scale-200.png -------------------------------------------------------------------------------- /example/windows/example/Assets/Square44x44Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonday/react-native-orientation-locker/d67716620199137b7b53df835b735625039f92e6/example/windows/example/Assets/Square44x44Logo.scale-200.png -------------------------------------------------------------------------------- /example/windows/example/Assets/Square44x44Logo.targetsize-24_altform-unplated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonday/react-native-orientation-locker/d67716620199137b7b53df835b735625039f92e6/example/windows/example/Assets/Square44x44Logo.targetsize-24_altform-unplated.png -------------------------------------------------------------------------------- /example/windows/example/Assets/StoreLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonday/react-native-orientation-locker/d67716620199137b7b53df835b735625039f92e6/example/windows/example/Assets/StoreLogo.png -------------------------------------------------------------------------------- /example/windows/example/Assets/Wide310x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonday/react-native-orientation-locker/d67716620199137b7b53df835b735625039f92e6/example/windows/example/Assets/Wide310x150Logo.scale-200.png -------------------------------------------------------------------------------- /example/windows/example/AutolinkedNativeModules.g.cpp: -------------------------------------------------------------------------------- 1 | // AutolinkedNativeModules.g.cpp contents generated by "react-native autolink-windows" 2 | // clang-format off 3 | #include "pch.h" 4 | #include "AutolinkedNativeModules.g.h" 5 | 6 | // Includes from react-native-orientation-locker 7 | #include 8 | 9 | namespace winrt::Microsoft::ReactNative 10 | { 11 | 12 | void RegisterAutolinkedNativeModulePackages(winrt::Windows::Foundation::Collections::IVector const& packageProviders) 13 | { 14 | // IReactPackageProviders from react-native-orientation-locker 15 | packageProviders.Append(winrt::OrientationWindows::ReactPackageProvider()); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /example/windows/example/AutolinkedNativeModules.g.h: -------------------------------------------------------------------------------- 1 | // AutolinkedNativeModules.g.h contents generated by "react-native autolink-windows" 2 | 3 | #pragma once 4 | 5 | namespace winrt::Microsoft::ReactNative 6 | { 7 | 8 | void RegisterAutolinkedNativeModulePackages(winrt::Windows::Foundation::Collections::IVector const& packageProviders); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /example/windows/example/AutolinkedNativeModules.g.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | {EF847B00-0D03-4611-93E3-40FFD0191998} 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/windows/example/MainPage.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "MainPage.h" 3 | #if __has_include("MainPage.g.cpp") 4 | #include "MainPage.g.cpp" 5 | #endif 6 | 7 | #include "App.h" 8 | 9 | 10 | 11 | using namespace winrt; 12 | using namespace Windows::UI::Xaml; 13 | 14 | namespace winrt::example::implementation 15 | { 16 | MainPage::MainPage() 17 | { 18 | InitializeComponent(); 19 | auto app = Application::Current().as(); 20 | ReactRootView().ReactNativeHost(app->Host()); 21 | } 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /example/windows/example/MainPage.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "MainPage.g.h" 3 | #include 4 | 5 | 6 | namespace winrt::example::implementation 7 | { 8 | struct MainPage : MainPageT 9 | { 10 | MainPage(); 11 | }; 12 | } 13 | 14 | namespace winrt::example::factory_implementation 15 | { 16 | struct MainPage : MainPageT 17 | { 18 | }; 19 | } 20 | 21 | 22 | -------------------------------------------------------------------------------- /example/windows/example/MainPage.idl: -------------------------------------------------------------------------------- 1 | namespace example 2 | { 3 | [default_interface] 4 | runtimeclass MainPage : Windows.UI.Xaml.Controls.Page 5 | { 6 | MainPage(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /example/windows/example/MainPage.xaml: -------------------------------------------------------------------------------- 1 | 11 | 16 | 17 | -------------------------------------------------------------------------------- /example/windows/example/Package.appxmanifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 8 | 9 | 13 | 14 | 15 | 16 | 17 | example 18 | chiaramooney 19 | Assets\StoreLogo.png 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /example/windows/example/PropertySheet.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /example/windows/example/ReactPackageProvider.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "ReactPackageProvider.h" 3 | #include "NativeModules.h" 4 | 5 | 6 | using namespace winrt::Microsoft::ReactNative; 7 | 8 | namespace winrt::example::implementation 9 | { 10 | 11 | void ReactPackageProvider::CreatePackage(IReactPackageBuilder const &packageBuilder) noexcept 12 | { 13 | AddAttributedModules(packageBuilder); 14 | } 15 | 16 | } // namespace winrt::example::implementation 17 | 18 | 19 | -------------------------------------------------------------------------------- /example/windows/example/ReactPackageProvider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "winrt/Microsoft.ReactNative.h" 4 | 5 | 6 | namespace winrt::example::implementation 7 | { 8 | struct ReactPackageProvider : winrt::implements 9 | { 10 | public: // IReactPackageProvider 11 | void CreatePackage(winrt::Microsoft::ReactNative::IReactPackageBuilder const &packageBuilder) noexcept; 12 | }; 13 | } // namespace winrt::example::implementation 14 | 15 | 16 | -------------------------------------------------------------------------------- /example/windows/example/example.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | true 6 | true 7 | true 8 | {aafade29-e73e-40a9-a75e-e5d1745134b6} 9 | example 10 | example 11 | en-US 12 | 16.0 13 | true 14 | Windows Store 15 | 10.0 16 | 10.0.18362.0 17 | 10.0.16299.0 18 | example_TemporaryKey.pfx 19 | 020D17FE66D88D3255EE6903D2841EBDBEE00CBB 20 | password 21 | 22 | 23 | 24 | $([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), 'node_modules\react-native-windows\package.json'))\node_modules\react-native-windows\ 25 | 26 | 27 | 28 | Debug 29 | ARM 30 | 31 | 32 | Debug 33 | ARM64 34 | 35 | 36 | Debug 37 | Win32 38 | 39 | 40 | Debug 41 | x64 42 | 43 | 44 | Release 45 | ARM 46 | 47 | 48 | Release 49 | ARM64 50 | 51 | 52 | Release 53 | Win32 54 | 55 | 56 | Release 57 | x64 58 | 59 | 60 | 61 | Application 62 | Unicode 63 | 64 | 65 | true 66 | true 67 | 68 | 69 | false 70 | true 71 | false 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | Use 90 | pch.h 91 | $(IntDir)pch.pch 92 | Level4 93 | %(AdditionalOptions) /bigobj 94 | 4453;28204 95 | 96 | 97 | 98 | 99 | _DEBUG;%(PreprocessorDefinitions) 100 | 101 | 102 | 103 | 104 | NDEBUG;%(PreprocessorDefinitions) 105 | 106 | 107 | 108 | 109 | MainPage.xaml 110 | Code 111 | 112 | 113 | 114 | 115 | 116 | App.xaml 117 | 118 | 119 | 120 | 121 | Designer 122 | 123 | 124 | 125 | 126 | Designer 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | MainPage.xaml 141 | Code 142 | 143 | 144 | 145 | 146 | Create 147 | 148 | 149 | App.xaml 150 | 151 | 152 | 153 | 154 | 155 | App.xaml 156 | 157 | 158 | MainPage.xaml 159 | Code 160 | 161 | 162 | 163 | 164 | 165 | 166 | false 167 | 168 | 169 | 170 | 171 | Designer 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | This project references targets in your node_modules\react-native-windows folder. The missing file is {0}. 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 192 | 193 | 194 | 195 | 196 | 197 | -------------------------------------------------------------------------------- /example/windows/example/example.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /example/windows/example/example_TemporaryKey.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonday/react-native-orientation-locker/d67716620199137b7b53df835b735625039f92e6/example/windows/example/example_TemporaryKey.pfx -------------------------------------------------------------------------------- /example/windows/example/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /example/windows/example/pch.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | -------------------------------------------------------------------------------- /example/windows/example/pch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define NOMINMAX 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | -------------------------------------------------------------------------------- /iOS/RCTOrientation.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 52EA30BE22DB68DA00018871 /* Orientation.m in Sources */ = {isa = PBXBuildFile; fileRef = 52EA30BD22DB68DA00018871 /* Orientation.m */; }; 11 | 52EA30BF22DB68DA00018871 /* Orientation.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 52EA30BC22DB68DA00018871 /* Orientation.h */; }; 12 | 52EA30D222DB6A0800018871 /* Orientation.m in Sources */ = {isa = PBXBuildFile; fileRef = 52EA30BD22DB68DA00018871 /* Orientation.m */; }; 13 | /* End PBXBuildFile section */ 14 | 15 | /* Begin PBXCopyFilesBuildPhase section */ 16 | 52EA30B722DB68DA00018871 /* CopyFiles */ = { 17 | isa = PBXCopyFilesBuildPhase; 18 | buildActionMask = 2147483647; 19 | dstPath = "include/$(PRODUCT_NAME)"; 20 | dstSubfolderSpec = 16; 21 | files = ( 22 | 52EA30BF22DB68DA00018871 /* Orientation.h in CopyFiles */, 23 | ); 24 | runOnlyForDeploymentPostprocessing = 0; 25 | }; 26 | 52EA30C722DB69B600018871 /* CopyFiles */ = { 27 | isa = PBXCopyFilesBuildPhase; 28 | buildActionMask = 2147483647; 29 | dstPath = "include/$(PRODUCT_NAME)"; 30 | dstSubfolderSpec = 16; 31 | files = ( 32 | ); 33 | runOnlyForDeploymentPostprocessing = 0; 34 | }; 35 | /* End PBXCopyFilesBuildPhase section */ 36 | 37 | /* Begin PBXFileReference section */ 38 | 52EA30B922DB68DA00018871 /* libRCTOrientation.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTOrientation.a; sourceTree = BUILT_PRODUCTS_DIR; }; 39 | 52EA30BC22DB68DA00018871 /* Orientation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Orientation.h; sourceTree = ""; }; 40 | 52EA30BD22DB68DA00018871 /* Orientation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Orientation.m; sourceTree = ""; }; 41 | 52EA30C922DB69B600018871 /* libRCTOrientation-tvOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libRCTOrientation-tvOS.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 42 | /* End PBXFileReference section */ 43 | 44 | /* Begin PBXFrameworksBuildPhase section */ 45 | 52EA30B622DB68DA00018871 /* Frameworks */ = { 46 | isa = PBXFrameworksBuildPhase; 47 | buildActionMask = 2147483647; 48 | files = ( 49 | ); 50 | runOnlyForDeploymentPostprocessing = 0; 51 | }; 52 | 52EA30C622DB69B600018871 /* Frameworks */ = { 53 | isa = PBXFrameworksBuildPhase; 54 | buildActionMask = 2147483647; 55 | files = ( 56 | ); 57 | runOnlyForDeploymentPostprocessing = 0; 58 | }; 59 | /* End PBXFrameworksBuildPhase section */ 60 | 61 | /* Begin PBXGroup section */ 62 | 52EA30B022DB68DA00018871 = { 63 | isa = PBXGroup; 64 | children = ( 65 | 52EA30BB22DB68DA00018871 /* RCTOrientation */, 66 | 52EA30BA22DB68DA00018871 /* Products */, 67 | ); 68 | sourceTree = ""; 69 | }; 70 | 52EA30BA22DB68DA00018871 /* Products */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | 52EA30B922DB68DA00018871 /* libRCTOrientation.a */, 74 | 52EA30C922DB69B600018871 /* libRCTOrientation-tvOS.a */, 75 | ); 76 | name = Products; 77 | sourceTree = ""; 78 | }; 79 | 52EA30BB22DB68DA00018871 /* RCTOrientation */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | 52EA30BC22DB68DA00018871 /* Orientation.h */, 83 | 52EA30BD22DB68DA00018871 /* Orientation.m */, 84 | ); 85 | path = RCTOrientation; 86 | sourceTree = ""; 87 | }; 88 | /* End PBXGroup section */ 89 | 90 | /* Begin PBXNativeTarget section */ 91 | 52EA30B822DB68DA00018871 /* RCTOrientation */ = { 92 | isa = PBXNativeTarget; 93 | buildConfigurationList = 52EA30C222DB68DA00018871 /* Build configuration list for PBXNativeTarget "RCTOrientation" */; 94 | buildPhases = ( 95 | 52EA30B522DB68DA00018871 /* Sources */, 96 | 52EA30B622DB68DA00018871 /* Frameworks */, 97 | 52EA30B722DB68DA00018871 /* CopyFiles */, 98 | ); 99 | buildRules = ( 100 | ); 101 | dependencies = ( 102 | ); 103 | name = RCTOrientation; 104 | productName = RCTOrientation; 105 | productReference = 52EA30B922DB68DA00018871 /* libRCTOrientation.a */; 106 | productType = "com.apple.product-type.library.static"; 107 | }; 108 | 52EA30C822DB69B600018871 /* RCTOrientation-tvOS */ = { 109 | isa = PBXNativeTarget; 110 | buildConfigurationList = 52EA30CF22DB69B600018871 /* Build configuration list for PBXNativeTarget "RCTOrientation-tvOS" */; 111 | buildPhases = ( 112 | 52EA30C522DB69B600018871 /* Sources */, 113 | 52EA30C622DB69B600018871 /* Frameworks */, 114 | 52EA30C722DB69B600018871 /* CopyFiles */, 115 | ); 116 | buildRules = ( 117 | ); 118 | dependencies = ( 119 | ); 120 | name = "RCTOrientation-tvOS"; 121 | productName = "RCTOrientation-tvOS"; 122 | productReference = 52EA30C922DB69B600018871 /* libRCTOrientation-tvOS.a */; 123 | productType = "com.apple.product-type.library.static"; 124 | }; 125 | /* End PBXNativeTarget section */ 126 | 127 | /* Begin PBXProject section */ 128 | 52EA30B122DB68DA00018871 /* Project object */ = { 129 | isa = PBXProject; 130 | attributes = { 131 | LastUpgradeCheck = 0900; 132 | ORGANIZATIONNAME = Wonday; 133 | TargetAttributes = { 134 | 52EA30B822DB68DA00018871 = { 135 | CreatedOnToolsVersion = 6.1.1; 136 | }; 137 | 52EA30C822DB69B600018871 = { 138 | CreatedOnToolsVersion = 6.1.1; 139 | }; 140 | }; 141 | }; 142 | buildConfigurationList = 52EA30B422DB68DA00018871 /* Build configuration list for PBXProject "RCTOrientation" */; 143 | compatibilityVersion = "Xcode 3.2"; 144 | developmentRegion = English; 145 | hasScannedForEncodings = 0; 146 | knownRegions = ( 147 | en, 148 | ); 149 | mainGroup = 52EA30B022DB68DA00018871; 150 | productRefGroup = 52EA30BA22DB68DA00018871 /* Products */; 151 | projectDirPath = ""; 152 | projectRoot = ""; 153 | targets = ( 154 | 52EA30B822DB68DA00018871 /* RCTOrientation */, 155 | 52EA30C822DB69B600018871 /* RCTOrientation-tvOS */, 156 | ); 157 | }; 158 | /* End PBXProject section */ 159 | 160 | /* Begin PBXSourcesBuildPhase section */ 161 | 52EA30B522DB68DA00018871 /* Sources */ = { 162 | isa = PBXSourcesBuildPhase; 163 | buildActionMask = 2147483647; 164 | files = ( 165 | 52EA30BE22DB68DA00018871 /* Orientation.m in Sources */, 166 | ); 167 | runOnlyForDeploymentPostprocessing = 0; 168 | }; 169 | 52EA30C522DB69B600018871 /* Sources */ = { 170 | isa = PBXSourcesBuildPhase; 171 | buildActionMask = 2147483647; 172 | files = ( 173 | 52EA30D222DB6A0800018871 /* Orientation.m in Sources */, 174 | ); 175 | runOnlyForDeploymentPostprocessing = 0; 176 | }; 177 | /* End PBXSourcesBuildPhase section */ 178 | 179 | /* Begin XCBuildConfiguration section */ 180 | 52EA30C022DB68DA00018871 /* Debug */ = { 181 | isa = XCBuildConfiguration; 182 | buildSettings = { 183 | ALWAYS_SEARCH_USER_PATHS = NO; 184 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 185 | CLANG_CXX_LIBRARY = "libc++"; 186 | CLANG_ENABLE_MODULES = YES; 187 | CLANG_ENABLE_OBJC_ARC = YES; 188 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 189 | CLANG_WARN_BOOL_CONVERSION = YES; 190 | CLANG_WARN_COMMA = YES; 191 | CLANG_WARN_CONSTANT_CONVERSION = YES; 192 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 193 | CLANG_WARN_EMPTY_BODY = YES; 194 | CLANG_WARN_ENUM_CONVERSION = YES; 195 | CLANG_WARN_INFINITE_RECURSION = YES; 196 | CLANG_WARN_INT_CONVERSION = YES; 197 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 198 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 199 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 200 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 201 | CLANG_WARN_STRICT_PROTOTYPES = YES; 202 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 203 | CLANG_WARN_UNREACHABLE_CODE = YES; 204 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 205 | COPY_PHASE_STRIP = NO; 206 | ENABLE_STRICT_OBJC_MSGSEND = YES; 207 | ENABLE_TESTABILITY = YES; 208 | GCC_C_LANGUAGE_STANDARD = gnu99; 209 | GCC_DYNAMIC_NO_PIC = NO; 210 | GCC_NO_COMMON_BLOCKS = YES; 211 | GCC_OPTIMIZATION_LEVEL = 0; 212 | GCC_PREPROCESSOR_DEFINITIONS = ( 213 | "DEBUG=1", 214 | "$(inherited)", 215 | ); 216 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 217 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 218 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 219 | GCC_WARN_UNDECLARED_SELECTOR = YES; 220 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 221 | GCC_WARN_UNUSED_FUNCTION = YES; 222 | GCC_WARN_UNUSED_VARIABLE = YES; 223 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 224 | MTL_ENABLE_DEBUG_INFO = YES; 225 | ONLY_ACTIVE_ARCH = YES; 226 | SDKROOT = iphoneos; 227 | }; 228 | name = Debug; 229 | }; 230 | 52EA30C122DB68DA00018871 /* Release */ = { 231 | isa = XCBuildConfiguration; 232 | buildSettings = { 233 | ALWAYS_SEARCH_USER_PATHS = NO; 234 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 235 | CLANG_CXX_LIBRARY = "libc++"; 236 | CLANG_ENABLE_MODULES = YES; 237 | CLANG_ENABLE_OBJC_ARC = YES; 238 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 239 | CLANG_WARN_BOOL_CONVERSION = YES; 240 | CLANG_WARN_COMMA = YES; 241 | CLANG_WARN_CONSTANT_CONVERSION = YES; 242 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 243 | CLANG_WARN_EMPTY_BODY = YES; 244 | CLANG_WARN_ENUM_CONVERSION = YES; 245 | CLANG_WARN_INFINITE_RECURSION = YES; 246 | CLANG_WARN_INT_CONVERSION = YES; 247 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 248 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 249 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 250 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 251 | CLANG_WARN_STRICT_PROTOTYPES = YES; 252 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 253 | CLANG_WARN_UNREACHABLE_CODE = YES; 254 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 255 | COPY_PHASE_STRIP = YES; 256 | ENABLE_NS_ASSERTIONS = NO; 257 | ENABLE_STRICT_OBJC_MSGSEND = YES; 258 | GCC_C_LANGUAGE_STANDARD = gnu99; 259 | GCC_NO_COMMON_BLOCKS = YES; 260 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 261 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 262 | GCC_WARN_UNDECLARED_SELECTOR = YES; 263 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 264 | GCC_WARN_UNUSED_FUNCTION = YES; 265 | GCC_WARN_UNUSED_VARIABLE = YES; 266 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 267 | MTL_ENABLE_DEBUG_INFO = NO; 268 | SDKROOT = iphoneos; 269 | VALIDATE_PRODUCT = YES; 270 | }; 271 | name = Release; 272 | }; 273 | 52EA30C322DB68DA00018871 /* Debug */ = { 274 | isa = XCBuildConfiguration; 275 | buildSettings = { 276 | HEADER_SEARCH_PATHS = ( 277 | "$(inherited)", 278 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 279 | "$(SRCROOT)/../../React/**", 280 | "$(SRCROOT)/../../react-native/React/**", 281 | ); 282 | LIBRARY_SEARCH_PATHS = "$(inherited)"; 283 | OTHER_LDFLAGS = "-ObjC"; 284 | PRODUCT_NAME = "RCTOrientation"; 285 | SKIP_INSTALL = YES; 286 | }; 287 | name = Debug; 288 | }; 289 | 52EA30C422DB68DA00018871 /* Release */ = { 290 | isa = XCBuildConfiguration; 291 | buildSettings = { 292 | HEADER_SEARCH_PATHS = ( 293 | "$(inherited)", 294 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 295 | "$(SRCROOT)/../../React/**", 296 | "$(SRCROOT)/../../react-native/React/**", 297 | ); 298 | LIBRARY_SEARCH_PATHS = "$(inherited)"; 299 | OTHER_LDFLAGS = "-ObjC"; 300 | PRODUCT_NAME = "RCTOrientation"; 301 | SKIP_INSTALL = YES; 302 | }; 303 | name = Release; 304 | }; 305 | 52EA30D022DB69B600018871 /* Debug */ = { 306 | isa = XCBuildConfiguration; 307 | buildSettings = { 308 | HEADER_SEARCH_PATHS = ( 309 | "$(inherited)", 310 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 311 | "$(SRCROOT)/../../React/**", 312 | "$(SRCROOT)/../../react-native/React/**", 313 | ); 314 | LIBRARY_SEARCH_PATHS = "$(inherited)"; 315 | OTHER_LDFLAGS = "-ObjC"; 316 | PRODUCT_NAME = "RCTOrientation-tvOS"; 317 | SKIP_INSTALL = YES; 318 | SUPPORTED_PLATFORMS = "appletvsimulator appletvos"; 319 | }; 320 | name = Debug; 321 | }; 322 | 52EA30D122DB69B600018871 /* Release */ = { 323 | isa = XCBuildConfiguration; 324 | buildSettings = { 325 | HEADER_SEARCH_PATHS = ( 326 | "$(inherited)", 327 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 328 | "$(SRCROOT)/../../React/**", 329 | "$(SRCROOT)/../../react-native/React/**", 330 | ); 331 | LIBRARY_SEARCH_PATHS = "$(inherited)"; 332 | OTHER_LDFLAGS = "-ObjC"; 333 | PRODUCT_NAME = "RCTOrientation-tvOS"; 334 | SKIP_INSTALL = YES; 335 | SUPPORTED_PLATFORMS = "appletvsimulator appletvos"; 336 | }; 337 | name = Release; 338 | }; 339 | /* End XCBuildConfiguration section */ 340 | 341 | /* Begin XCConfigurationList section */ 342 | 52EA30B422DB68DA00018871 /* Build configuration list for PBXProject "RCTOrientation" */ = { 343 | isa = XCConfigurationList; 344 | buildConfigurations = ( 345 | 52EA30C022DB68DA00018871 /* Debug */, 346 | 52EA30C122DB68DA00018871 /* Release */, 347 | ); 348 | defaultConfigurationIsVisible = 0; 349 | defaultConfigurationName = Release; 350 | }; 351 | 52EA30C222DB68DA00018871 /* Build configuration list for PBXNativeTarget "RCTOrientation" */ = { 352 | isa = XCConfigurationList; 353 | buildConfigurations = ( 354 | 52EA30C322DB68DA00018871 /* Debug */, 355 | 52EA30C422DB68DA00018871 /* Release */, 356 | ); 357 | defaultConfigurationIsVisible = 0; 358 | defaultConfigurationName = Release; 359 | }; 360 | 52EA30CF22DB69B600018871 /* Build configuration list for PBXNativeTarget "RCTOrientation-tvOS" */ = { 361 | isa = XCConfigurationList; 362 | buildConfigurations = ( 363 | 52EA30D022DB69B600018871 /* Debug */, 364 | 52EA30D122DB69B600018871 /* Release */, 365 | ); 366 | defaultConfigurationIsVisible = 0; 367 | defaultConfigurationName = Release; 368 | }; 369 | /* End XCConfigurationList section */ 370 | }; 371 | rootObject = 52EA30B122DB68DA00018871 /* Project object */; 372 | } 373 | -------------------------------------------------------------------------------- /iOS/RCTOrientation/Orientation.h: -------------------------------------------------------------------------------- 1 | // 2 | // react-native-orientation-locker 3 | // Orientation.h 4 | // 5 | // Created by Wonday on 17/5/12. 6 | // Copyright (c) wonday.org All rights reserved. 7 | // 8 | 9 | 10 | #import 11 | #import 12 | #import 13 | #import 14 | 15 | @interface Orientation : RCTEventEmitter 16 | #if (!TARGET_OS_TV) 17 | + (void)setOrientation: (UIInterfaceOrientationMask)orientation; 18 | + (UIInterfaceOrientationMask)getOrientation; 19 | #endif 20 | @end 21 | -------------------------------------------------------------------------------- /iOS/RCTOrientation/Orientation.m: -------------------------------------------------------------------------------- 1 | // 2 | // react-native-orientation-locker 3 | // Orientation.m 4 | // 5 | // Created by Wonday on 17/5/12. 6 | // Copyright (c) wonday.org All rights reserved. 7 | // 8 | 9 | 10 | #import "Orientation.h" 11 | 12 | 13 | @implementation Orientation 14 | { 15 | #if (!TARGET_OS_TV) 16 | UIInterfaceOrientation _lastOrientation; 17 | UIInterfaceOrientation _lastDeviceOrientation; 18 | BOOL _disableFaceUpDown; 19 | #endif 20 | BOOL _isLocking; 21 | } 22 | 23 | #if (!TARGET_OS_TV) 24 | static UIInterfaceOrientationMask _orientationMask = UIInterfaceOrientationMaskAll; 25 | 26 | + (void)setOrientation: (UIInterfaceOrientationMask)orientationMask { 27 | _orientationMask = orientationMask; 28 | } 29 | 30 | + (UIInterfaceOrientationMask)getOrientation { 31 | return _orientationMask; 32 | } 33 | 34 | - (NSArray *)supportedEvents 35 | { 36 | return @[@"orientationDidChange",@"deviceOrientationDidChange",@"lockDidChange"]; 37 | } 38 | 39 | - (instancetype)init 40 | { 41 | if ((self = [super init])) { 42 | _lastOrientation = [self getInterfaceOrientation]; 43 | _lastDeviceOrientation = [self getDeviceOrientation]; 44 | _isLocking = NO; 45 | _disableFaceUpDown = NO; 46 | 47 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil]; 48 | [self addListener:@"orientationDidChange"]; 49 | } 50 | return self; 51 | } 52 | 53 | - (void)dealloc 54 | { 55 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 56 | [self removeListeners:1]; 57 | } 58 | 59 | - (UIInterfaceOrientation)getInterfaceOrientation 60 | { 61 | if(@available(iOS 13, *)) { 62 | UIInterfaceOrientation orientation = UIInterfaceOrientationUnknown; 63 | UIWindowScene *activeScene = [self getWindowScene]; 64 | if (activeScene != nil && [activeScene isKindOfClass:[UIWindowScene class]]) { 65 | UIWindowScene *windowScene = (UIWindowScene *)activeScene; 66 | orientation = windowScene.interfaceOrientation; 67 | } 68 | 69 | #if DEBUG 70 | if(orientation == UIInterfaceOrientationUnknown) { 71 | NSLog(@"Device orientation is unknown."); 72 | } 73 | #endif 74 | 75 | return orientation; 76 | } else { 77 | return [UIApplication sharedApplication].statusBarOrientation; 78 | } 79 | } 80 | 81 | - (UIInterfaceOrientation)getDeviceOrientation { 82 | UIInterfaceOrientation deviceOrientation = (UIInterfaceOrientation) [UIDevice currentDevice].orientation; 83 | 84 | BOOL isFaceUpDown = deviceOrientation == UIDeviceOrientationFaceUp || deviceOrientation == UIDeviceOrientationFaceDown; 85 | if (_disableFaceUpDown && isFaceUpDown) { 86 | return [self getInterfaceOrientation]; 87 | } 88 | 89 | return deviceOrientation; 90 | } 91 | 92 | - (void)deviceOrientationDidChange:(NSNotification *)notification 93 | { 94 | UIInterfaceOrientation orientation = [self getInterfaceOrientation]; 95 | UIInterfaceOrientation deviceOrientation = [self getDeviceOrientation]; 96 | 97 | // do not send Unknown Orientation 98 | if (deviceOrientation==UIInterfaceOrientationUnknown) { 99 | return; 100 | } 101 | 102 | if (orientation!=UIInterfaceOrientationUnknown && orientation!=_lastOrientation) { 103 | [self sendEventWithName:@"orientationDidChange" body:@{@"orientation": [self getOrientationStr:orientation]}]; 104 | _lastOrientation = orientation; 105 | } 106 | 107 | // when call lockToXXX, not sent deviceOrientationDidChange 108 | if (!_isLocking && deviceOrientation!=_lastDeviceOrientation) { 109 | [self sendEventWithName:@"deviceOrientationDidChange" body:@{@"deviceOrientation":[self getOrientationStr:deviceOrientation]}]; 110 | _lastDeviceOrientation = deviceOrientation; 111 | } 112 | } 113 | 114 | - (UIWindowScene *)getWindowScene { 115 | NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects]; 116 | for (id connectedScene in array) { 117 | if ([connectedScene isKindOfClass:[UIWindowScene class]]) { 118 | return connectedScene; 119 | } 120 | } 121 | return nil; 122 | } 123 | 124 | - (NSString *)getOrientationStr: (UIInterfaceOrientation)orientation { 125 | 126 | NSString *orientationStr; 127 | switch (orientation) { 128 | case UIInterfaceOrientationPortrait: 129 | orientationStr = @"PORTRAIT"; 130 | break; 131 | 132 | case UIInterfaceOrientationLandscapeLeft: 133 | orientationStr = @"LANDSCAPE-RIGHT"; 134 | break; 135 | 136 | case UIInterfaceOrientationLandscapeRight: 137 | orientationStr = @"LANDSCAPE-LEFT"; 138 | break; 139 | 140 | case UIInterfaceOrientationPortraitUpsideDown: 141 | orientationStr = @"PORTRAIT-UPSIDEDOWN"; 142 | break; 143 | 144 | case UIDeviceOrientationFaceUp: 145 | orientationStr = @"FACE-UP"; 146 | break; 147 | 148 | case UIDeviceOrientationFaceDown: 149 | orientationStr = @"FACE-DOWN"; 150 | break; 151 | 152 | default: 153 | orientationStr = @"UNKNOWN"; 154 | break; 155 | } 156 | return orientationStr; 157 | } 158 | 159 | - (void)lockToOrientation:(UIInterfaceOrientation) newOrientation usingMask:(UIInterfaceOrientationMask) mask { 160 | // set a flag so that no deviceOrientationDidChange events are sent to JS 161 | _isLocking = YES; 162 | NSString* orientation = @"orientation"; 163 | 164 | [Orientation setOrientation:mask]; 165 | 166 | if (@available(iOS 16.0, *)) { 167 | UIWindowScene *windowScene = [self getWindowScene]; 168 | if (windowScene != nil) { 169 | UIWindowSceneGeometryPreferencesIOS *geometryPreferences = [[UIWindowSceneGeometryPreferencesIOS alloc] initWithInterfaceOrientations:mask]; 170 | [windowScene requestGeometryUpdateWithPreferences:geometryPreferences errorHandler:^(NSError * _Nonnull error) { 171 | #if DEBUG 172 | if (error) { 173 | NSLog(@"Failed to update geometry with UIInterfaceOrientationMask: %@", error); 174 | } 175 | #endif 176 | }]; 177 | } 178 | } else { 179 | UIDevice* currentDevice = [UIDevice currentDevice]; 180 | 181 | [currentDevice setValue:@(UIInterfaceOrientationUnknown) forKey:orientation]; 182 | [currentDevice setValue:@(newOrientation) forKey:orientation]; 183 | } 184 | 185 | [UIViewController attemptRotationToDeviceOrientation]; 186 | 187 | [self sendEventWithName:@"lockDidChange" body:@{orientation: [self getOrientationStr:newOrientation]}]; 188 | 189 | _isLocking = NO; 190 | } 191 | 192 | #else 193 | 194 | - (NSArray *)supportedEvents 195 | { 196 | return @[]; 197 | } 198 | 199 | #endif 200 | 201 | RCT_EXPORT_MODULE(); 202 | 203 | RCT_EXPORT_METHOD(configure:(NSDictionary *)options) 204 | { 205 | #if DEBUG 206 | NSLog(@"Configure called with options: %@", options); 207 | #endif 208 | 209 | #if (!TARGET_OS_TV) 210 | NSNumber *disableFaceUpDown = [options objectForKey:@"disableFaceUpDown"]; 211 | _disableFaceUpDown = [disableFaceUpDown boolValue]; 212 | #endif 213 | } 214 | 215 | RCT_EXPORT_METHOD(getOrientation:(RCTResponseSenderBlock)callback) 216 | { 217 | #if (!TARGET_OS_TV) 218 | dispatch_async(dispatch_get_main_queue(), ^{ 219 | UIInterfaceOrientation orientation = [self getInterfaceOrientation]; 220 | NSString *orientationStr = [self getOrientationStr:orientation]; 221 | callback(@[orientationStr]); 222 | }); 223 | #endif 224 | } 225 | 226 | RCT_EXPORT_METHOD(getDeviceOrientation:(RCTResponseSenderBlock)callback) 227 | { 228 | #if (!TARGET_OS_TV) 229 | dispatch_async(dispatch_get_main_queue(), ^{ 230 | UIInterfaceOrientation deviceOrientation = [self getDeviceOrientation]; 231 | NSString *orientationStr = [self getOrientationStr:deviceOrientation]; 232 | callback(@[orientationStr]); 233 | }); 234 | #endif 235 | } 236 | 237 | RCT_EXPORT_METHOD(lockToPortrait) 238 | { 239 | #if (!TARGET_OS_TV) 240 | dispatch_async(dispatch_get_main_queue(), ^{ 241 | [self lockToOrientation:UIInterfaceOrientationPortrait usingMask:UIInterfaceOrientationMaskPortrait]; 242 | }); 243 | #endif 244 | } 245 | 246 | RCT_EXPORT_METHOD(lockToPortraitUpsideDown) 247 | { 248 | #if (!TARGET_OS_TV) 249 | dispatch_async(dispatch_get_main_queue(), ^{ 250 | [self lockToOrientation:UIInterfaceOrientationPortraitUpsideDown usingMask:UIInterfaceOrientationMaskPortraitUpsideDown]; 251 | }); 252 | #endif 253 | } 254 | 255 | RCT_EXPORT_METHOD(lockToLandscape) 256 | { 257 | #if DEBUG 258 | NSLog(@"Locking to Landscape"); 259 | #endif 260 | 261 | #if (!TARGET_OS_TV) 262 | dispatch_async(dispatch_get_main_queue(), ^{ 263 | // set a flag so that no deviceOrientationDidChange events are sent to JS 264 | self->_isLocking = YES; 265 | 266 | UIInterfaceOrientation deviceOrientation = self->_lastDeviceOrientation; 267 | 268 | UIInterfaceOrientation orientation = [self getInterfaceOrientation]; 269 | NSString *orientationStr = [self getOrientationStr:orientation]; 270 | 271 | // when call lockXXX, make sure to sent orientationDidChange event to JS 272 | [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationUnknown] forKey:@"orientation"]; 273 | 274 | if ([orientationStr isEqualToString:@"LANDSCAPE-RIGHT"]) { 275 | [Orientation setOrientation:UIInterfaceOrientationMaskLandscape]; 276 | [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeLeft] forKey:@"orientation"]; 277 | } else { 278 | [Orientation setOrientation:UIInterfaceOrientationMaskLandscape]; 279 | [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeRight] forKey:@"orientation"]; 280 | } 281 | 282 | // restore device orientation 283 | [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: deviceOrientation] forKey:@"orientation"]; 284 | 285 | [UIViewController attemptRotationToDeviceOrientation]; 286 | 287 | // send a lock event 288 | [self sendEventWithName:@"lockDidChange" body:@{@"orientation":@"LANDSCAPE-LEFT"}]; 289 | 290 | self->_isLocking = NO; 291 | }); 292 | #endif 293 | } 294 | 295 | RCT_EXPORT_METHOD(lockToLandscapeRight) 296 | { 297 | #if DEBUG 298 | NSLog(@"Locking to Landscape Right"); 299 | #endif 300 | 301 | #if (!TARGET_OS_TV) 302 | dispatch_async(dispatch_get_main_queue(), ^{ 303 | [self lockToOrientation:UIInterfaceOrientationLandscapeLeft usingMask:UIInterfaceOrientationMaskLandscapeLeft]; 304 | }); 305 | #endif 306 | } 307 | 308 | RCT_EXPORT_METHOD(lockToLandscapeLeft) 309 | { 310 | #if DEBUG 311 | NSLog(@"Locking to Landscape Left"); 312 | #endif 313 | #if (!TARGET_OS_TV) 314 | dispatch_async(dispatch_get_main_queue(), ^{ 315 | [self lockToOrientation:UIInterfaceOrientationLandscapeRight usingMask:UIInterfaceOrientationMaskLandscapeRight]; 316 | }); 317 | #endif 318 | } 319 | 320 | RCT_EXPORT_METHOD(lockToAllOrientationsButUpsideDown) 321 | { 322 | #if DEBUG 323 | NSLog(@"Locking to all except upside down"); 324 | #endif 325 | #if (!TARGET_OS_TV) 326 | dispatch_async(dispatch_get_main_queue(), ^{ 327 | [self lockToOrientation:UIInterfaceOrientationPortrait usingMask:UIInterfaceOrientationMaskAllButUpsideDown]; 328 | }); 329 | #endif 330 | } 331 | 332 | RCT_EXPORT_METHOD(unlockAllOrientations) 333 | { 334 | #if DEBUG 335 | NSLog(@"Unlocking All Orientations"); 336 | #endif 337 | 338 | #if (!TARGET_OS_TV) 339 | dispatch_async(dispatch_get_main_queue(), ^{ 340 | [self lockToOrientation:UIInterfaceOrientationUnknown usingMask:UIInterfaceOrientationMaskAll]; 341 | }); 342 | #endif 343 | } 344 | 345 | - (NSDictionary *)constantsToExport 346 | { 347 | #if (!TARGET_OS_TV) 348 | UIInterfaceOrientation orientation = [self getInterfaceOrientation]; 349 | NSString *orientationStr = [self getOrientationStr:orientation]; 350 | 351 | return @{@"initialOrientation": orientationStr}; 352 | #endif 353 | return nil; 354 | } 355 | 356 | + (BOOL)requiresMainQueueSetup 357 | { 358 | return YES; 359 | } 360 | 361 | @end 362 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017-present, Wonday (@wonday.org) 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the MIT-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | import React from 'react'; 10 | 11 | export enum OrientationType { 12 | "PORTRAIT" = "PORTRAIT", 13 | "PORTRAIT-UPSIDEDOWN" = "PORTRAIT-UPSIDEDOWN", 14 | "LANDSCAPE-LEFT" = "LANDSCAPE-LEFT", 15 | "LANDSCAPE-RIGHT" = "LANDSCAPE-RIGHT", 16 | "FACE-UP" = "FACE-UP", 17 | "FACE-DOWN" = "FACE-DOWN", 18 | "UNKNOWN" = "UNKNOWN", 19 | } 20 | 21 | export const UNLOCK = 'UNLOCK'; 22 | export const PORTRAIT = 'PORTRAIT'; 23 | export const LANDSCAPE = 'LANDSCAPE'; 24 | export const LANDSCAPE_LEFT = 'LANDSCAPE_LEFT'; 25 | export const LANDSCAPE_RIGHT = 'LANDSCAPE_RIGHT'; 26 | export const PORTRAIT_UPSIDE_DOWN = 'PORTRAIT_UPSIDE_DOWN'; 27 | export const ALL_ORIENTATIONS_BUT_UPSIDE_DOWN = 'ALL_ORIENTATIONS_BUT_UPSIDE_DOWN'; 28 | 29 | export interface OrientationLockerProps { 30 | orientation: typeof UNLOCK | typeof PORTRAIT | typeof LANDSCAPE | typeof LANDSCAPE_LEFT | typeof LANDSCAPE_RIGHT | typeof PORTRAIT_UPSIDE_DOWN | typeof ALL_ORIENTATIONS_BUT_UPSIDE_DOWN; 31 | onChange?: (orientation: OrientationType) => void; 32 | onDeviceChange?: (deviceOrientation: OrientationType) => void; 33 | } 34 | 35 | type IOSConfigurationOptions = { 36 | disableFaceUpDown: boolean; 37 | } 38 | 39 | export const OrientationLocker: React.ComponentType; 40 | 41 | declare class Orientation { 42 | static configure(options: IOSConfigurationOptions): void; 43 | 44 | static addOrientationListener(callback: (orientation: OrientationType) => void): void; 45 | 46 | static removeOrientationListener(callback: (orientation: OrientationType) => void): void; 47 | 48 | static addDeviceOrientationListener(callback: (deviceOrientation: OrientationType) => void): void; 49 | 50 | static removeDeviceOrientationListener(callback: (deviceOrientation: OrientationType) => void): void; 51 | 52 | static addLockListener(callback: (orientation: OrientationType) => void): void; 53 | 54 | static removeLockListener(callback: (orientation: OrientationType) => void): void; 55 | 56 | static removeAllListeners(): void; 57 | 58 | static getInitialOrientation(): OrientationType; 59 | 60 | static isLocked(): boolean; 61 | 62 | static lockToPortrait(): void; 63 | 64 | static lockToLandscape(): void; 65 | 66 | static lockToLandscapeLeft(): void; 67 | 68 | static lockToAllOrientationsButUpsideDown(): void; 69 | 70 | static lockToLandscapeRight(): void; 71 | 72 | static lockToPortraitUpsideDown(): void; 73 | 74 | static unlockAllOrientations(): void; 75 | 76 | static getOrientation(callback: (orientation: OrientationType) => void): void; 77 | 78 | static getDeviceOrientation(callback: (orientation: OrientationType) => void): void; 79 | 80 | static getAutoRotateState(callback: (state: boolean) => void): void; 81 | } 82 | 83 | export default Orientation; 84 | 85 | declare function useOrientationChange(listener: (orientation: OrientationType) => void): void; 86 | 87 | declare function useDeviceOrientationChange(listener: (orientation: OrientationType) => void): void; 88 | 89 | declare function useLockListener(listener: (orientation: OrientationType) => void): void; 90 | 91 | export { 92 | useOrientationChange, 93 | useDeviceOrientationChange, 94 | useLockListener, 95 | } 96 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // 2 | // react-native-orientation-locker 3 | // 4 | // 5 | // Created by Wonday on 17/5/12. 6 | // Copyright (c) wonday.org All rights reserved. 7 | // 8 | 9 | "use strict"; 10 | 11 | import Orientation from './src/orientation'; 12 | 13 | export * from './src/hooks'; 14 | export * from './src/OrientationLocker'; 15 | 16 | export const OrientationType = { 17 | PORTRAIT: 'PORTRAIT', 18 | 'PORTRAIT-UPSIDEDOWN': 'PORTRAIT-UPSIDEDOWN', 19 | 'LANDSCAPE-LEFT': 'LANDSCAPE-LEFT', 20 | 'LANDSCAPE-RIGHT': 'LANDSCAPE-RIGHT', 21 | 'FACE-UP': 'FACE-UP', 22 | 'FACE-DOWN': 'FACE-DOWN', 23 | UNKNOWN: 'UNKNOWN', 24 | }; 25 | 26 | export default Orientation; 27 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-orientation-locker", 3 | "version": "1.7.0", 4 | "summary": "A react-native module that can listen on orientation changing of device", 5 | "description": "A react-native module that can listen on orientation changing of device, get current orientation, lock to preferred orientation.", 6 | "homepage": "https://github.com/wonday/react-native-orientation-locker", 7 | "main": "index.js", 8 | "types": "index.d.ts", 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/wonday/react-native-orientation-locker.git" 12 | }, 13 | "keywords": [ 14 | "orientation", 15 | "react-native", 16 | "android", 17 | "ios", 18 | "windows", 19 | "screen" 20 | ], 21 | "author": { 22 | "name": "Wonday", 23 | "url": "https://github.com/wonday" 24 | }, 25 | "license": "MIT", 26 | "bugs": { 27 | "url": "https://github.com/wonday/react-native-orientation-locker/issues" 28 | }, 29 | "dependencies": { 30 | }, 31 | "peerDependencies": { 32 | "react": ">=16.13.1", 33 | "react-native": ">=0.63.2", 34 | "react-native-windows": ">=0.63.3" 35 | }, 36 | "peerDependenciesMeta": { 37 | "react-native-windows": { 38 | "optional": true 39 | } 40 | }, 41 | "devDependencies": { 42 | "react": "16.13.1", 43 | "react-native": "0.69.12", 44 | "react-native-windows": "^0.63.3" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /react-native-orientation-locker.podspec: -------------------------------------------------------------------------------- 1 | require 'json' 2 | 3 | package = JSON.parse(File.read(File.join(__dir__, 'package.json'))) 4 | 5 | Pod::Spec.new do |s| 6 | s.name = package['name'] 7 | s.version = package['version'] 8 | s.summary = package['summary'] 9 | s.description = package['description'] 10 | s.author = package['author']['name'] 11 | s.license = package['license'] 12 | s.homepage = package['homepage'] 13 | s.source = { :git => 'https://github.com/wonday/react-native-orientation-locker.git', :tag => "v#{s.version}" } 14 | s.requires_arc = true 15 | s.ios.deployment_target = '8.0' 16 | s.tvos.deployment_target = '11.0' 17 | s.preserve_paths = 'README.md', 'package.json', 'index.js' 18 | s.source_files = 'iOS/**/*.{h,m}' 19 | s.dependency 'React-Core' 20 | end 21 | -------------------------------------------------------------------------------- /react-native.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | dependency: { 3 | platforms: { 4 | windows: { 5 | sourceDir: 'windows', 6 | solutionFile: 'OrientationWindows.sln', 7 | projects: [ 8 | { 9 | projectFile: 'OrientationWindows/OrientationWindows.vcxproj', 10 | directDependency: true, 11 | } 12 | ], 13 | }, 14 | }, 15 | }, 16 | }; 17 | -------------------------------------------------------------------------------- /src/OrientationLocker.js: -------------------------------------------------------------------------------- 1 | import { useEffect, useRef } from 'react'; 2 | import Orientation from './orientation'; 3 | 4 | export const UNLOCK = 'UNLOCK'; 5 | export const PORTRAIT = 'PORTRAIT'; 6 | export const LANDSCAPE = 'LANDSCAPE'; 7 | export const LANDSCAPE_LEFT = 'LANDSCAPE_LEFT'; 8 | export const LANDSCAPE_RIGHT = 'LANDSCAPE_RIGHT'; 9 | export const PORTRAIT_UPSIDE_DOWN = 'PORTRAIT_UPSIDE_DOWN'; 10 | export const ALL_ORIENTATIONS_BUT_UPSIDE_DOWN = 'ALL_ORIENTATIONS_BUT_UPSIDE_DOWN'; 11 | 12 | const stack = []; 13 | 14 | let immediateId; 15 | 16 | function update() { 17 | clearImmediate(immediateId); 18 | immediateId = setImmediate(() => { 19 | let orientation; 20 | let length = stack.length; 21 | while (!orientation && length--) { 22 | orientation = stack[length].orientation; 23 | } 24 | 25 | switch (orientation) { 26 | case UNLOCK: 27 | Orientation.unlockAllOrientations(); 28 | break; 29 | case PORTRAIT: 30 | Orientation.lockToPortrait(); 31 | break; 32 | case LANDSCAPE: 33 | Orientation.lockToLandscape(); 34 | break; 35 | case LANDSCAPE_LEFT: 36 | Orientation.lockToLandscapeLeft(); 37 | break; 38 | case LANDSCAPE_RIGHT: 39 | Orientation.lockToLandscapeRight(); 40 | break; 41 | case PORTRAIT_UPSIDE_DOWN: 42 | Orientation.lockToPortraitUpsideDown(); 43 | break; 44 | case ALL_ORIENTATIONS_BUT_UPSIDE_DOWN: 45 | Orientation.lockToAllOrientationsButUpsideDown(); 46 | break; 47 | } 48 | }); 49 | } 50 | 51 | export function OrientationLocker({ 52 | orientation, 53 | onChange, 54 | onDeviceChange, 55 | }) { 56 | const stackEntry = useRef({}); 57 | 58 | // didMount: add to stack 59 | useEffect(() => { 60 | const { current } = stackEntry; 61 | stack.push(current); 62 | 63 | // willUnmount: remove from stack 64 | return () => { 65 | const index = stack.indexOf(current); 66 | if (index !== -1) { 67 | stack.splice(index, 1); 68 | } 69 | update(); 70 | }; 71 | }, []); 72 | 73 | // props.orientation 74 | useEffect(() => { 75 | stackEntry.current.orientation = orientation; 76 | update(); 77 | }, [orientation]); 78 | 79 | // props.onChange 80 | useEffect(() => { 81 | if (onChange) { 82 | Orientation.addOrientationListener(onChange); 83 | return () => Orientation.removeOrientationListener(onChange); 84 | } 85 | }, [onChange]); 86 | 87 | // props.onDeviceChange 88 | useEffect(() => { 89 | if (onDeviceChange) { 90 | Orientation.addDeviceOrientationListener(onDeviceChange); 91 | return () => Orientation.removeDeviceOrientationListener(onDeviceChange); 92 | } 93 | }, [onDeviceChange]); 94 | 95 | return null; 96 | } 97 | -------------------------------------------------------------------------------- /src/hooks/index.js: -------------------------------------------------------------------------------- 1 | export * from './useOrientationChange'; 2 | export * from './useDeviceOrientationChange'; 3 | export * from './useLockListener'; -------------------------------------------------------------------------------- /src/hooks/useDeviceOrientationChange.js: -------------------------------------------------------------------------------- 1 | import { useRef, useEffect } from 'react'; 2 | import Orientation from '../orientation' 3 | 4 | export function useDeviceOrientationChange(callback) { 5 | const savedCallback = useRef(); 6 | 7 | useEffect(() => { 8 | savedCallback.current = callback; 9 | }, [callback]); 10 | 11 | useEffect(() => { 12 | function listener(ori) { 13 | savedCallback.current(ori); 14 | } 15 | const initial = Orientation.getInitialOrientation(); 16 | listener(initial); 17 | Orientation.addDeviceOrientationListener(listener); 18 | 19 | return () => { 20 | Orientation.removeDeviceOrientationListener(listener); 21 | }; 22 | }, []); 23 | } -------------------------------------------------------------------------------- /src/hooks/useLockListener.js: -------------------------------------------------------------------------------- 1 | import { useRef, useEffect } from 'react'; 2 | import Orientation from '../orientation' 3 | 4 | export function useLockListener(callback) { 5 | const savedCallback = useRef(); 6 | 7 | useEffect(() => { 8 | savedCallback.current = callback; 9 | }, [callback]); 10 | 11 | useEffect(() => { 12 | function listener(ori) { 13 | savedCallback.current(ori); 14 | } 15 | Orientation.addLockListener(listener); 16 | 17 | return () => { 18 | Orientation.removeLockListener(listener); 19 | }; 20 | }, []); 21 | } -------------------------------------------------------------------------------- /src/hooks/useOrientationChange.js: -------------------------------------------------------------------------------- 1 | import { useRef, useEffect } from 'react'; 2 | import Orientation from '../orientation' 3 | 4 | export function useOrientationChange(callback) { 5 | const savedCallback = useRef(); 6 | 7 | useEffect(() => { 8 | savedCallback.current = callback; 9 | }, [callback]); 10 | 11 | useEffect(() => { 12 | function listener(ori) { 13 | savedCallback.current(ori); 14 | } 15 | const initial = Orientation.getInitialOrientation(); 16 | listener(initial); 17 | Orientation.addOrientationListener(listener); 18 | 19 | return () => { 20 | Orientation.removeOrientationListener(listener); 21 | }; 22 | }, []); 23 | } -------------------------------------------------------------------------------- /src/orientation.android.js: -------------------------------------------------------------------------------- 1 | // 2 | // react-native-orientation-locker 3 | // 4 | // 5 | // Created by Wonday on 17/5/12. 6 | // Copyright (c) wonday.org All rights reserved. 7 | // 8 | 9 | "use strict"; 10 | const OrientationNative = require("react-native").NativeModules.Orientation; 11 | const { NativeEventEmitter } = require("react-native"); 12 | let LocalEventEmitter; 13 | 14 | var listeners = {}; 15 | 16 | var id = 0; 17 | var META = "__listener_id"; 18 | 19 | var locked = false; 20 | 21 | function getKey(listener) { 22 | if (!listener.hasOwnProperty(META)) { 23 | if (!Object.isExtensible(listener)) { 24 | return "F"; 25 | } 26 | Object.defineProperty(listener, META, { 27 | value: "L" + ++id, 28 | }); 29 | } 30 | return listener[META]; 31 | } 32 | 33 | export default class Orientation { 34 | static configure = (_options) => { 35 | // ios only 36 | }; 37 | 38 | static getOrientation = (cb) => { 39 | OrientationNative.getOrientation((orientation) => { 40 | cb(orientation); 41 | }); 42 | }; 43 | 44 | static getDeviceOrientation = (cb) => { 45 | OrientationNative.getDeviceOrientation((deviceOrientation) => { 46 | cb(deviceOrientation); 47 | }); 48 | }; 49 | 50 | static isLocked = () => { 51 | return locked; 52 | }; 53 | 54 | static lockToPortrait = () => { 55 | locked = true; 56 | OrientationNative.lockToPortrait(); 57 | }; 58 | 59 | static lockToPortraitUpsideDown = () => { 60 | locked = true; 61 | OrientationNative.lockToPortraitUpsideDown(); 62 | }; 63 | 64 | static lockToLandscape = () => { 65 | locked = true; 66 | OrientationNative.lockToLandscape(); 67 | }; 68 | 69 | static lockToLandscapeRight = () => { 70 | locked = true; 71 | OrientationNative.lockToLandscapeRight(); 72 | }; 73 | 74 | static lockToLandscapeLeft = () => { 75 | locked = true; 76 | OrientationNative.lockToLandscapeLeft(); 77 | }; 78 | 79 | // OrientationMaskAllButUpsideDown 80 | static lockToAllOrientationsButUpsideDown = () => { 81 | locked = true; 82 | }; 83 | 84 | static unlockAllOrientations = () => { 85 | locked = false; 86 | OrientationNative.unlockAllOrientations(); 87 | }; 88 | 89 | static addOrientationListener = (cb) => { 90 | var key = getKey(cb); 91 | LocalEventEmitter = 92 | LocalEventEmitter ?? new NativeEventEmitter(OrientationNative); 93 | listeners[key] = LocalEventEmitter.addListener( 94 | "orientationDidChange", 95 | (body) => { 96 | cb(body.orientation); 97 | } 98 | ); 99 | }; 100 | 101 | static removeOrientationListener = (cb) => { 102 | var key = getKey(cb); 103 | if (!listeners[key]) { 104 | return; 105 | } 106 | listeners[key].remove(); 107 | listeners[key] = null; 108 | }; 109 | 110 | static addDeviceOrientationListener = (cb) => { 111 | var key = getKey(cb); 112 | LocalEventEmitter = 113 | LocalEventEmitter ?? new NativeEventEmitter(OrientationNative); 114 | listeners[key] = LocalEventEmitter.addListener( 115 | "deviceOrientationDidChange", 116 | (body) => { 117 | cb(body.deviceOrientation); 118 | } 119 | ); 120 | }; 121 | 122 | static removeDeviceOrientationListener = (cb) => { 123 | var key = getKey(cb); 124 | if (!listeners[key]) { 125 | return; 126 | } 127 | listeners[key].remove(); 128 | listeners[key] = null; 129 | }; 130 | 131 | static addLockListener = (cb) => { 132 | var key = getKey(cb); 133 | LocalEventEmitter = 134 | LocalEventEmitter ?? new NativeEventEmitter(OrientationNative); 135 | listeners[key] = LocalEventEmitter.addListener("lockDidChange", (body) => { 136 | cb(body.orientation); 137 | }); 138 | }; 139 | 140 | static removeLockListener = (cb) => { 141 | var key = getKey(cb); 142 | if (!listeners[key]) { 143 | return; 144 | } 145 | listeners[key].remove(); 146 | listeners[key] = null; 147 | }; 148 | 149 | static removeAllListeners = () => { 150 | for (var key in listeners) { 151 | if (!listeners[key]) { 152 | continue; 153 | } 154 | listeners[key].remove(); 155 | listeners[key] = null; 156 | } 157 | }; 158 | 159 | static getInitialOrientation = () => { 160 | return OrientationNative.initialOrientation; 161 | }; 162 | 163 | static getAutoRotateState = (cb) => { 164 | OrientationNative.getAutoRotateState((state) => { 165 | cb(state); 166 | }); 167 | }; 168 | } 169 | -------------------------------------------------------------------------------- /src/orientation.ios.js: -------------------------------------------------------------------------------- 1 | // 2 | // react-native-orientation-locker 3 | // 4 | // 5 | // Created by Wonday on 17/5/12. 6 | // Copyright (c) wonday.org All rights reserved. 7 | // 8 | 9 | "use strict"; 10 | const OrientationNative = require("react-native").NativeModules.Orientation; 11 | const { NativeEventEmitter } = require("react-native"); 12 | const LocalEventEmitter = new NativeEventEmitter(OrientationNative); 13 | 14 | var listeners = {}; 15 | 16 | var id = 0; 17 | var META = "__listener_id"; 18 | 19 | var locked = false; 20 | 21 | function getKey(listener) { 22 | if (!listener.hasOwnProperty(META)) { 23 | if (!Object.isExtensible(listener)) { 24 | return "F"; 25 | } 26 | Object.defineProperty(listener, META, { 27 | value: "L" + ++id 28 | }); 29 | } 30 | return listener[META]; 31 | } 32 | 33 | export default class Orientation { 34 | static configure = (options) => { 35 | OrientationNative.configure(options); 36 | }; 37 | 38 | static getOrientation = cb => { 39 | OrientationNative.getOrientation(orientation => { 40 | cb(orientation); 41 | }); 42 | }; 43 | 44 | static getDeviceOrientation = cb => { 45 | OrientationNative.getDeviceOrientation(deviceOrientation => { 46 | cb(deviceOrientation); 47 | }); 48 | }; 49 | 50 | static isLocked = () => { 51 | return locked; 52 | }; 53 | 54 | static lockToPortrait = () => { 55 | locked = true; 56 | OrientationNative.lockToPortrait(); 57 | }; 58 | 59 | static lockToPortraitUpsideDown = () => { 60 | locked = true; 61 | OrientationNative.lockToPortraitUpsideDown(); 62 | }; 63 | 64 | static lockToLandscape = () => { 65 | locked = true; 66 | OrientationNative.lockToLandscape(); 67 | }; 68 | 69 | static lockToLandscapeRight = () => { 70 | locked = true; 71 | OrientationNative.lockToLandscapeRight(); 72 | }; 73 | 74 | static lockToLandscapeLeft = () => { 75 | locked = true; 76 | OrientationNative.lockToLandscapeLeft(); 77 | }; 78 | 79 | // OrientationMaskAllButUpsideDown 80 | static lockToAllOrientationsButUpsideDown = () => { 81 | locked = true; 82 | OrientationNative.lockToAllOrientationsButUpsideDown(); 83 | }; 84 | 85 | static unlockAllOrientations = () => { 86 | locked = false; 87 | OrientationNative.unlockAllOrientations(); 88 | }; 89 | 90 | static addOrientationListener = cb => { 91 | var key = getKey(cb); 92 | listeners[key] = LocalEventEmitter.addListener( 93 | "orientationDidChange", 94 | body => { 95 | cb(body.orientation); 96 | } 97 | ); 98 | }; 99 | 100 | static removeOrientationListener = cb => { 101 | var key = getKey(cb); 102 | if (!listeners[key]) { 103 | return; 104 | } 105 | listeners[key].remove(); 106 | listeners[key] = null; 107 | }; 108 | 109 | static addDeviceOrientationListener = cb => { 110 | var key = getKey(cb); 111 | listeners[key] = LocalEventEmitter.addListener( 112 | "deviceOrientationDidChange", 113 | body => { 114 | cb(body.deviceOrientation); 115 | } 116 | ); 117 | }; 118 | 119 | static removeDeviceOrientationListener = cb => { 120 | var key = getKey(cb); 121 | if (!listeners[key]) { 122 | return; 123 | } 124 | listeners[key].remove(); 125 | listeners[key] = null; 126 | }; 127 | 128 | static addLockListener = cb => { 129 | var key = getKey(cb); 130 | listeners[key] = LocalEventEmitter.addListener("lockDidChange", body => { 131 | cb(body.orientation); 132 | }); 133 | }; 134 | 135 | static removeLockListener = cb => { 136 | var key = getKey(cb); 137 | if (!listeners[key]) { 138 | return; 139 | } 140 | listeners[key].remove(); 141 | listeners[key] = null; 142 | }; 143 | 144 | static removeAllListeners = () => { 145 | for (var key in listeners) { 146 | if (!listeners[key]) { 147 | continue; 148 | } 149 | listeners[key].remove(); 150 | listeners[key] = null; 151 | } 152 | }; 153 | 154 | static getInitialOrientation = () => { 155 | return OrientationNative.initialOrientation; 156 | }; 157 | 158 | static getAutoRotateState = cb => { 159 | cb(true); // iOS not implement 160 | }; 161 | } 162 | -------------------------------------------------------------------------------- /src/orientation.js: -------------------------------------------------------------------------------- 1 | // 2 | // react-native-orientation-locker 3 | // 4 | // 5 | // Created by Wonday on 17/5/12. 6 | // Copyright (c) wonday.org All rights reserved. 7 | // 8 | 9 | "use strict"; 10 | 11 | export default class Orientation { 12 | static configure = options => {} 13 | 14 | static getOrientation = cb => { 15 | cb("UNKNOWN"); 16 | }; 17 | 18 | static getDeviceOrientation = cb => { 19 | cb("UNKNOWN"); 20 | }; 21 | 22 | static isLocked = () => { 23 | return false; 24 | }; 25 | 26 | static lockToPortrait = () => {}; 27 | 28 | static lockToPortraitUpsideDown = () => {}; 29 | 30 | static lockToLandscape = () => {}; 31 | 32 | static lockToLandscapeRight = () => {}; 33 | 34 | static lockToLandscapeLeft = () => {}; 35 | 36 | // OrientationMaskAllButUpsideDown 37 | static lockToAllOrientationsButUpsideDown = () => {}; 38 | 39 | static unlockAllOrientations = () => {}; 40 | 41 | static addOrientationListener = cb => {}; 42 | 43 | static removeOrientationListener = cb => {}; 44 | 45 | static addDeviceOrientationListener = cb => {}; 46 | 47 | static removeDeviceOrientationListener = cb => {}; 48 | 49 | static addLockListener = cb => {}; 50 | 51 | static removeLockListener = cb => {}; 52 | 53 | static removeAllListeners = () => {}; 54 | 55 | static getInitialOrientation = () => { 56 | return "UNKNOWN"; 57 | }; 58 | 59 | static getAutoRotateState = cb => { 60 | cb(true); 61 | }; 62 | } 63 | -------------------------------------------------------------------------------- /src/orientation.windows.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | const OrientationNative = require("react-native").NativeModules.OrientationLocker; 3 | const { NativeEventEmitter } = require("react-native"); 4 | const LocalEventEmitter = new NativeEventEmitter(OrientationNative); 5 | 6 | var listeners = {}; 7 | 8 | var id = 0; 9 | var META = "__listener_id"; 10 | 11 | var locked = false; 12 | 13 | function getKey(listener) { 14 | if (!listener.hasOwnProperty(META)) { 15 | if (!Object.isExtensible(listener)) { 16 | return "F"; 17 | } 18 | Object.defineProperty(listener, META, { 19 | value: "L" + ++id 20 | }); 21 | } 22 | return listener[META]; 23 | } 24 | 25 | export default class Orientation { 26 | static configure = (_options) => { 27 | // ios only 28 | }; 29 | 30 | static getOrientation = cb => { 31 | OrientationNative.getOrientation(orientation => { 32 | cb(orientation); 33 | }); 34 | }; 35 | 36 | static getDeviceOrientation = cb => { 37 | OrientationNative.getDeviceOrientation(deviceOrientation => { 38 | cb(deviceOrientation); 39 | }); 40 | }; 41 | 42 | static isLocked = () => { 43 | return locked; 44 | }; 45 | 46 | static lockToPortrait = () => { 47 | locked = true; 48 | OrientationNative.lockToPortrait(); 49 | }; 50 | 51 | static lockToPortraitUpsideDown = () => { 52 | locked = true; 53 | OrientationNative.lockToPortraitUpsideDown(); 54 | }; 55 | 56 | static lockToLandscape = () => { 57 | locked = true; 58 | OrientationNative.lockToLandscape(); 59 | }; 60 | 61 | static lockToLandscapeRight = () => { 62 | locked = true; 63 | OrientationNative.lockToLandscapeRight(); 64 | }; 65 | 66 | static lockToLandscapeLeft = () => { 67 | locked = true; 68 | OrientationNative.lockToLandscapeLeft(); 69 | }; 70 | 71 | // OrientationMaskAllButUpsideDown 72 | static lockToAllOrientationsButUpsideDown = () => { 73 | locked = true; 74 | //OrientationNative.lockToAllOrientationsButUpsideDown(); 75 | }; 76 | 77 | static unlockAllOrientations = () => { 78 | locked = false; 79 | OrientationNative.unlockAllOrientations(); 80 | }; 81 | 82 | static addOrientationListener = cb => { 83 | var key = getKey(cb); 84 | listeners[key] = LocalEventEmitter.addListener( 85 | "orientationDidChange", 86 | body => { 87 | cb(body); 88 | } 89 | ); 90 | }; 91 | 92 | static removeOrientationListener = cb => { 93 | var key = getKey(cb); 94 | if (!listeners[key]) { 95 | return; 96 | } 97 | listeners[key].remove(); 98 | listeners[key] = null; 99 | }; 100 | 101 | static addDeviceOrientationListener = cb => { 102 | var key = getKey(cb); 103 | listeners[key] = LocalEventEmitter.addListener( 104 | "deviceOrientationDidChange", 105 | body => { 106 | cb(body); 107 | } 108 | ); 109 | }; 110 | 111 | static removeDeviceOrientationListener = cb => { 112 | var key = getKey(cb); 113 | if (!listeners[key]) { 114 | return; 115 | } 116 | listeners[key].remove(); 117 | listeners[key] = null; 118 | }; 119 | 120 | static addLockListener = cb => { 121 | var key = getKey(cb); 122 | listeners[key] = LocalEventEmitter.addListener("lockDidChange", body => { 123 | cb(body); 124 | }); 125 | }; 126 | 127 | static removeLockListener = cb => { 128 | var key = getKey(cb); 129 | if (!listeners[key]) { 130 | return; 131 | } 132 | listeners[key].remove(); 133 | listeners[key] = null; 134 | }; 135 | 136 | static removeAllListeners = () => { 137 | for (var key in listeners) { 138 | if (!listeners[key]) { 139 | continue; 140 | } 141 | listeners[key].remove(); 142 | listeners[key] = null; 143 | } 144 | }; 145 | 146 | static getInitialOrientation = () => { 147 | return OrientationNative.initialOrientation; 148 | }; 149 | 150 | static getAutoRotateState = cb => { 151 | cb(true); // iOS not implement 152 | }; 153 | } -------------------------------------------------------------------------------- /src/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "../index.js", 3 | "types": "../index.d.ts", 4 | "peerDependencies": { 5 | "react-native-windows": "^0.63.3", 6 | "react-native": "0.69.12" 7 | }, 8 | "devDependencies": { 9 | "react-native-windows": "^0.63.3", 10 | "react-native": "0.69.12", 11 | "react": "16.13.1" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /windows/.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.vspscc 94 | *.vssscc 95 | .builds 96 | *.pidb 97 | *.svclog 98 | *.scc 99 | 100 | # Chutzpah Test files 101 | _Chutzpah* 102 | 103 | # Visual C++ cache files 104 | ipch/ 105 | *.aps 106 | *.ncb 107 | *.opendb 108 | *.opensdf 109 | *.sdf 110 | *.cachefile 111 | *.VC.db 112 | *.VC.VC.opendb 113 | 114 | # Visual Studio profiler 115 | *.psess 116 | *.vsp 117 | *.vspx 118 | *.sap 119 | 120 | # Visual Studio Trace Files 121 | *.e2e 122 | 123 | # TFS 2012 Local Workspace 124 | $tf/ 125 | 126 | # Guidance Automation Toolkit 127 | *.gpState 128 | 129 | # ReSharper is a .NET coding add-in 130 | _ReSharper*/ 131 | *.[Rr]e[Ss]harper 132 | *.DotSettings.user 133 | 134 | # TeamCity is a build add-in 135 | _TeamCity* 136 | 137 | # DotCover is a Code Coverage Tool 138 | *.dotCover 139 | 140 | # AxoCover is a Code Coverage Tool 141 | .axoCover/* 142 | !.axoCover/settings.json 143 | 144 | # Coverlet is a free, cross platform Code Coverage Tool 145 | coverage*.json 146 | coverage*.xml 147 | coverage*.info 148 | 149 | # Visual Studio code coverage results 150 | *.coverage 151 | *.coveragexml 152 | 153 | # NCrunch 154 | _NCrunch_* 155 | .*crunch*.local.xml 156 | nCrunchTemp_* 157 | 158 | # MightyMoose 159 | *.mm.* 160 | AutoTest.Net/ 161 | 162 | # Web workbench (sass) 163 | .sass-cache/ 164 | 165 | # Installshield output folder 166 | [Ee]xpress/ 167 | 168 | # DocProject is a documentation generator add-in 169 | DocProject/buildhelp/ 170 | DocProject/Help/*.HxT 171 | DocProject/Help/*.HxC 172 | DocProject/Help/*.hhc 173 | DocProject/Help/*.hhk 174 | DocProject/Help/*.hhp 175 | DocProject/Help/Html2 176 | DocProject/Help/html 177 | 178 | # Click-Once directory 179 | publish/ 180 | 181 | # Publish Web Output 182 | *.[Pp]ublish.xml 183 | *.azurePubxml 184 | # Note: Comment the next line if you want to checkin your web deploy settings, 185 | # but database connection strings (with potential passwords) will be unencrypted 186 | *.pubxml 187 | *.publishproj 188 | 189 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 190 | # checkin your Azure Web App publish settings, but sensitive information contained 191 | # in these scripts will be unencrypted 192 | PublishScripts/ 193 | 194 | # NuGet Packages 195 | *.nupkg 196 | # NuGet Symbol Packages 197 | *.snupkg 198 | # The packages folder can be ignored because of Package Restore 199 | **/[Pp]ackages/* 200 | # except build/, which is used as an MSBuild target. 201 | !**/[Pp]ackages/build/ 202 | # Uncomment if necessary however generally it will be regenerated when needed 203 | #!**/[Pp]ackages/repositories.config 204 | # NuGet v3's project.json files produces more ignorable files 205 | *.nuget.props 206 | *.nuget.targets 207 | 208 | # Microsoft Azure Build Output 209 | csx/ 210 | *.build.csdef 211 | 212 | # Microsoft Azure Emulator 213 | ecf/ 214 | rcf/ 215 | 216 | # Windows Store app package directories and files 217 | AppPackages/ 218 | BundleArtifacts/ 219 | Package.StoreAssociation.xml 220 | _pkginfo.txt 221 | *.appx 222 | *.appxbundle 223 | *.appxupload 224 | 225 | # Visual Studio cache files 226 | # files ending in .cache can be ignored 227 | *.[Cc]ache 228 | # but keep track of directories ending in .cache 229 | !?*.[Cc]ache/ 230 | 231 | # Others 232 | ClientBin/ 233 | ~$* 234 | *~ 235 | *.dbmdl 236 | *.dbproj.schemaview 237 | *.jfm 238 | *.pfx 239 | *.publishsettings 240 | orleans.codegen.cs 241 | 242 | # Including strong name files can present a security risk 243 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 244 | #*.snk 245 | 246 | # Since there are multiple workflows, uncomment next line to ignore bower_components 247 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 248 | #bower_components/ 249 | 250 | # RIA/Silverlight projects 251 | Generated_Code/ 252 | 253 | # Backup & report files from converting an old project file 254 | # to a newer Visual Studio version. Backup files are not needed, 255 | # because we have git ;-) 256 | _UpgradeReport_Files/ 257 | Backup*/ 258 | UpgradeLog*.XML 259 | UpgradeLog*.htm 260 | ServiceFabricBackup/ 261 | *.rptproj.bak 262 | 263 | # SQL Server files 264 | *.mdf 265 | *.ldf 266 | *.ndf 267 | 268 | # Business Intelligence projects 269 | *.rdl.data 270 | *.bim.layout 271 | *.bim_*.settings 272 | *.rptproj.rsuser 273 | *- [Bb]ackup.rdl 274 | *- [Bb]ackup ([0-9]).rdl 275 | *- [Bb]ackup ([0-9][0-9]).rdl 276 | 277 | # Microsoft Fakes 278 | FakesAssemblies/ 279 | 280 | # GhostDoc plugin setting file 281 | *.GhostDoc.xml 282 | 283 | # Node.js Tools for Visual Studio 284 | .ntvs_analysis.dat 285 | node_modules/ 286 | 287 | # Visual Studio 6 build log 288 | *.plg 289 | 290 | # Visual Studio 6 workspace options file 291 | *.opt 292 | 293 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 294 | *.vbw 295 | 296 | # Visual Studio LightSwitch build output 297 | **/*.HTMLClient/GeneratedArtifacts 298 | **/*.DesktopClient/GeneratedArtifacts 299 | **/*.DesktopClient/ModelManifest.xml 300 | **/*.Server/GeneratedArtifacts 301 | **/*.Server/ModelManifest.xml 302 | _Pvt_Extensions 303 | 304 | # Paket dependency manager 305 | .paket/paket.exe 306 | paket-files/ 307 | 308 | # FAKE - F# Make 309 | .fake/ 310 | 311 | # CodeRush personal settings 312 | .cr/personal 313 | 314 | # Python Tools for Visual Studio (PTVS) 315 | __pycache__/ 316 | *.pyc 317 | 318 | # Cake - Uncomment if you are using it 319 | # tools/** 320 | # !tools/packages.config 321 | 322 | # Tabs Studio 323 | *.tss 324 | 325 | # Telerik's JustMock configuration file 326 | *.jmconfig 327 | 328 | # BizTalk build output 329 | *.btp.cs 330 | *.btm.cs 331 | *.odx.cs 332 | *.xsd.cs 333 | 334 | # OpenCover UI analysis results 335 | OpenCover/ 336 | 337 | # Azure Stream Analytics local run output 338 | ASALocalRun/ 339 | 340 | # MSBuild Binary and Structured Log 341 | *.binlog 342 | 343 | # NVidia Nsight GPU debugger configuration file 344 | *.nvuser 345 | 346 | # MFractors (Xamarin productivity tool) working folder 347 | .mfractor/ 348 | 349 | # Local History for Visual Studio 350 | .localhistory/ 351 | 352 | # BeatPulse healthcheck temp database 353 | healthchecksdb 354 | 355 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 356 | MigrationBackup/ 357 | 358 | # Ionide (cross platform F# VS Code tools) working folder 359 | .ionide/ 360 | 361 | # Fody - auto-generated XML schema 362 | FodyWeavers.xsd 363 | -------------------------------------------------------------------------------- /windows/OrientationWindows/OrientationWindows.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "OrientationWindows.h" 3 | 4 | using namespace winrt::Windows::Graphics::Display; 5 | using namespace winrt::Windows::UI::ViewManagement; 6 | using namespace winrt::Windows::Devices::Sensors; 7 | 8 | namespace OrientationWindows { 9 | 10 | void OrientationLockerModule::Initialize(React::ReactContext const& reactContext) noexcept { 11 | m_context = reactContext; 12 | m_deviceOrientationSensor = SimpleOrientationSensor::GetDefault(); 13 | if (m_deviceOrientationSensor != nullptr) 14 | { 15 | m_deviceOrientationChangedToken = m_deviceOrientationSensor.OrientationChanged({ this, &OrientationLockerModule::OnDeviceOrientationChanged }); 16 | } 17 | } 18 | 19 | void OrientationLockerModule::addListener(std::string) noexcept 20 | { 21 | // Keep: Required for RN built in Event Emitter Calls. 22 | } 23 | 24 | void OrientationLockerModule::removeListeners(int64_t) noexcept 25 | { 26 | // Keep: Required for RN built in Event Emitter Calls. 27 | } 28 | 29 | void OrientationLockerModule::GetOrientation(std::function cb) noexcept { 30 | m_context.UIDispatcher().Post([weakThis = weak_from_this(), this, cb]() { 31 | if (auto strongThis = weakThis.lock()) 32 | { 33 | const auto currentOrientation = m_displayInfo.CurrentOrientation(); 34 | cb(OrientationToString(currentOrientation)); 35 | return; 36 | } 37 | cb("UNKNOWN"); 38 | }); 39 | } 40 | 41 | void OrientationLockerModule::GetDeviceOrientation(std::function cb) noexcept { 42 | m_context.UIDispatcher().Post([weakThis = weak_from_this(), this, cb]() { 43 | if (auto strongThis = weakThis.lock()) 44 | { 45 | if (m_deviceOrientationSensor != nullptr) 46 | { 47 | const auto currentDeviceOrientation = m_deviceOrientationSensor.GetCurrentOrientation(); 48 | cb(DeviceOrientationToString(currentDeviceOrientation)); 49 | return; 50 | } 51 | } 52 | // No Orientation Sensor found on device 53 | cb("UNKNOWN"); 54 | }); 55 | } 56 | 57 | void OrientationLockerModule::LockToPortrait() noexcept { 58 | const auto mode = m_viewSettings.UserInteractionMode(); 59 | if (mode == UserInteractionMode::Touch) { 60 | if (m_displayInfo.AutoRotationPreferences() != DisplayOrientations::Portrait) { 61 | DisplayInformation::AutoRotationPreferences(DisplayOrientations::Portrait); 62 | LockDidChange("PORTRAIT"); 63 | } 64 | } 65 | } 66 | 67 | void OrientationLockerModule::LockToPortraitUpsideDown() noexcept { 68 | const auto mode = m_viewSettings.UserInteractionMode(); 69 | if (mode == UserInteractionMode::Touch) { 70 | if (m_displayInfo.AutoRotationPreferences() != DisplayOrientations::PortraitFlipped) { 71 | DisplayInformation::AutoRotationPreferences(DisplayOrientations::PortraitFlipped); 72 | LockDidChange("PORTRAIT-UPSIDEDOWN"); 73 | } 74 | } 75 | } 76 | 77 | void OrientationLockerModule::LockToLandscape() noexcept { 78 | const auto mode = m_viewSettings.UserInteractionMode(); 79 | if (mode == UserInteractionMode::Touch) { 80 | if (m_displayInfo.AutoRotationPreferences() != DisplayOrientations::Landscape) { 81 | DisplayInformation::AutoRotationPreferences(DisplayOrientations::Landscape); 82 | LockDidChange("LANDSCAPE"); 83 | } 84 | } 85 | } 86 | 87 | void OrientationLockerModule::LockToLandscapeRight() noexcept { 88 | const auto mode = m_viewSettings.UserInteractionMode(); 89 | if (mode == UserInteractionMode::Touch) { 90 | if (m_displayInfo.AutoRotationPreferences() != DisplayOrientations::LandscapeFlipped) { 91 | DisplayInformation::AutoRotationPreferences(DisplayOrientations::LandscapeFlipped); 92 | LockDidChange("LANDSCAPE-RIGHT"); 93 | } 94 | } 95 | } 96 | 97 | void OrientationLockerModule::LockToLandscapeLeft() noexcept { 98 | const auto mode = m_viewSettings.UserInteractionMode(); 99 | if (mode == UserInteractionMode::Touch) { 100 | if (m_displayInfo.AutoRotationPreferences() != DisplayOrientations::Landscape) { 101 | DisplayInformation::AutoRotationPreferences(DisplayOrientations::Landscape); 102 | LockDidChange("LANDSCAPE-LEFT"); 103 | } 104 | } 105 | } 106 | 107 | void OrientationLockerModule::UnlockAllOrientations() noexcept { 108 | const auto mode = m_viewSettings.UserInteractionMode(); 109 | if (mode == UserInteractionMode::Touch) { 110 | DisplayOrientations allOrientations = DisplayOrientations::Landscape | DisplayOrientations::LandscapeFlipped | DisplayOrientations::Portrait | DisplayOrientations::PortraitFlipped; 111 | if (m_displayInfo.AutoRotationPreferences() != allOrientations) { 112 | DisplayInformation::AutoRotationPreferences(allOrientations); 113 | GetOrientation(LockDidChange); 114 | } 115 | } 116 | } 117 | 118 | void OrientationLockerModule::GetConstants(React::ReactConstantProvider& provider) noexcept { 119 | if (!m_context.UIDispatcher().HasThreadAccess()) { 120 | const auto ghSetConstantsEvent = CreateEvent( 121 | nullptr, // default security attributes 122 | TRUE, // manual-reset event 123 | FALSE, // initial state is nonsignaled 124 | L"OrientationLockerModule_SetConstantsEvent" // object name 125 | ); 126 | if (ghSetConstantsEvent == nullptr) 127 | { 128 | assert(false); 129 | } 130 | m_context.UIDispatcher().Post([&provider, ghSetConstantsEvent, this]() { 131 | InitConstants(); 132 | provider.Add(L"initialOrientation", GetInitOrientation()); 133 | if (!SetEvent(ghSetConstantsEvent)) 134 | { 135 | assert(false); 136 | } 137 | }); 138 | const auto dwWaitResult = WaitForSingleObject( 139 | ghSetConstantsEvent, 140 | INFINITE); // wait period 141 | switch (dwWaitResult) 142 | { 143 | case WAIT_OBJECT_0: 144 | break; 145 | default: 146 | assert(false); 147 | } 148 | CloseHandle(ghSetConstantsEvent); 149 | } 150 | else { 151 | InitConstants(); 152 | provider.Add(L"initialOrientation", GetInitOrientation()); 153 | } 154 | } 155 | 156 | std::string OrientationLockerModule::OrientationToString(DisplayOrientations orientation) noexcept { 157 | std::string result; 158 | if (orientation == DisplayOrientations::Landscape) 159 | { 160 | result = "LANDSCAPE"; 161 | } 162 | else if (orientation == DisplayOrientations::Portrait) 163 | { 164 | result = "PORTRAIT"; 165 | } 166 | else if (orientation == DisplayOrientations::LandscapeFlipped) 167 | { 168 | result = "LANDSCAPE-RIGHT"; 169 | } 170 | else if (orientation == DisplayOrientations::PortraitFlipped) 171 | { 172 | result = "PORTRAIT-UPSIDEDOWN"; 173 | } 174 | return result; 175 | } 176 | 177 | std::string OrientationLockerModule::DeviceOrientationToString(SimpleOrientation orientation) noexcept { 178 | std::string result; 179 | if (orientation == SimpleOrientation::Facedown) 180 | { 181 | result = "FACE-DOWN"; 182 | } 183 | else if (orientation == SimpleOrientation::Faceup) 184 | { 185 | result = "FACE-UP"; 186 | } 187 | else if (orientation == SimpleOrientation::NotRotated) 188 | { 189 | result = "LANDSCAPE"; 190 | } 191 | else if (orientation == SimpleOrientation::Rotated90DegreesCounterclockwise) 192 | { 193 | result = "PORTRAIT-UPSIDEDOWN"; 194 | } 195 | else if (orientation == SimpleOrientation::Rotated180DegreesCounterclockwise) 196 | { 197 | result = "LANDSCAPE-RIGHT"; 198 | } 199 | else if (orientation == SimpleOrientation::Rotated270DegreesCounterclockwise) 200 | { 201 | result = "PORTRAIT"; 202 | } 203 | return result; 204 | } 205 | 206 | void OrientationLockerModule::OnOrientationChanged(DisplayInformation const&, winrt::Windows::Foundation::IInspectable const&) noexcept { 207 | GetOrientation(OrientationDidChange); 208 | } 209 | 210 | void OrientationLockerModule::OnDeviceOrientationChanged(SimpleOrientationSensor const&, SimpleOrientationSensorOrientationChangedEventArgs const&) noexcept { 211 | GetDeviceOrientation(DeviceOrientationDidChange); 212 | } 213 | 214 | void OrientationLockerModule::InitConstants() noexcept { 215 | m_displayInfo = DisplayInformation::GetForCurrentView(); 216 | m_viewSettings = UIViewSettings::GetForCurrentView(); 217 | m_initialOrientation = OrientationToString(m_displayInfo.CurrentOrientation()); 218 | m_orientationChangedToken = m_displayInfo.OrientationChanged({ this, &OrientationLockerModule::OnOrientationChanged }); 219 | } 220 | 221 | std::string OrientationLockerModule::GetInitOrientation() noexcept { 222 | return m_initialOrientation; 223 | } 224 | } 225 | -------------------------------------------------------------------------------- /windows/OrientationWindows/OrientationWindows.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | DllCanUnloadNow = WINRT_CanUnloadNow PRIVATE 3 | DllGetActivationFactory = WINRT_GetActivationFactory PRIVATE 4 | -------------------------------------------------------------------------------- /windows/OrientationWindows/OrientationWindows.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "pch.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace winrt::Microsoft::ReactNative; 9 | 10 | namespace OrientationWindows { 11 | 12 | REACT_MODULE(OrientationLockerModule, L"OrientationLocker"); 13 | struct OrientationLockerModule : public std::enable_shared_from_this 14 | { 15 | REACT_INIT(Initialize) 16 | void Initialize(React::ReactContext const& reactContext) noexcept; 17 | 18 | // Only used to suppress some warnings. Not actually used at this time. 19 | REACT_METHOD(addListener); 20 | void addListener(std::string) noexcept; 21 | 22 | // Only used to suppress some warnings. Not actually used at this time. 23 | REACT_METHOD(removeListeners); 24 | void removeListeners(int64_t) noexcept; 25 | 26 | REACT_METHOD(GetOrientation, L"getOrientation"); 27 | void GetOrientation(std::function cb) noexcept; 28 | 29 | REACT_METHOD(GetDeviceOrientation, L"getDeviceOrientation"); 30 | void GetDeviceOrientation(std::function cb) noexcept; 31 | 32 | REACT_METHOD(LockToPortrait, L"lockToPortrait"); 33 | void LockToPortrait() noexcept; 34 | 35 | REACT_METHOD(LockToPortraitUpsideDown, L"lockToPortraitUpsideDown"); 36 | void LockToPortraitUpsideDown() noexcept; 37 | 38 | REACT_METHOD(LockToLandscape, L"lockToLandscape"); 39 | void LockToLandscape() noexcept; 40 | 41 | REACT_METHOD(LockToLandscapeRight, L"lockToLandscapeRight"); 42 | void LockToLandscapeRight() noexcept; 43 | 44 | REACT_METHOD(LockToLandscapeLeft, L"lockToLandscapeLeft"); 45 | void LockToLandscapeLeft() noexcept; 46 | 47 | REACT_METHOD(UnlockAllOrientations, L"unlockAllOrientations"); 48 | void UnlockAllOrientations() noexcept; 49 | 50 | REACT_EVENT(OrientationDidChange, L"orientationDidChange"); 51 | std::function OrientationDidChange; 52 | 53 | REACT_EVENT(DeviceOrientationDidChange, L"deviceOrientationDidChange"); 54 | std::function DeviceOrientationDidChange; 55 | 56 | REACT_EVENT(LockDidChange, L"lockDidChange"); 57 | std::function LockDidChange; 58 | 59 | REACT_CONSTANT_PROVIDER(GetConstants) 60 | void GetConstants(React::ReactConstantProvider& provider) noexcept; 61 | 62 | private: 63 | 64 | static std::string OrientationToString(winrt::Windows::Graphics::Display::DisplayOrientations orientations) noexcept; 65 | 66 | static std::string DeviceOrientationToString(winrt::Windows::Devices::Sensors::SimpleOrientation orientation) noexcept; 67 | 68 | void OnOrientationChanged(winrt::Windows::Graphics::Display::DisplayInformation const&, winrt::Windows::Foundation::IInspectable const&) noexcept; 69 | 70 | void OnDeviceOrientationChanged(winrt::Windows::Devices::Sensors::SimpleOrientationSensor const&, winrt::Windows::Devices::Sensors::SimpleOrientationSensorOrientationChangedEventArgs const&) noexcept; 71 | 72 | void InitConstants() noexcept; 73 | 74 | std::string GetInitOrientation() noexcept; 75 | 76 | winrt::Windows::Graphics::Display::DisplayInformation m_displayInfo{ nullptr }; 77 | 78 | winrt::event_token m_orientationChangedToken{}; 79 | 80 | winrt::Windows::UI::ViewManagement::UIViewSettings m_viewSettings{ nullptr }; 81 | 82 | winrt::Microsoft::ReactNative::ReactContext m_context; 83 | 84 | std::string m_initialOrientation; 85 | 86 | winrt::Windows::Devices::Sensors::SimpleOrientationSensor m_deviceOrientationSensor{ nullptr }; 87 | 88 | winrt::event_token m_deviceOrientationChangedToken{}; 89 | }; 90 | } 91 | -------------------------------------------------------------------------------- /windows/OrientationWindows/OrientationWindows.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | 4 | #include "resource.h" 5 | 6 | #define APSTUDIO_READONLY_SYMBOLS 7 | ///////////////////////////////////////////////////////////////////////////// 8 | // 9 | // Generated from the TEXTINCLUDE 2 resource. 10 | // 11 | #include "winres.h" 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | #undef APSTUDIO_READONLY_SYMBOLS 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // English (United States) resources 18 | 19 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 20 | LANGUAGE 9, 1 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | #endif // English (United States) resources 48 | ///////////////////////////////////////////////////////////////////////////// 49 | 50 | 51 | 52 | #ifndef APSTUDIO_INVOKED 53 | ///////////////////////////////////////////////////////////////////////////// 54 | // 55 | // Generated from the TEXTINCLUDE 3 resource. 56 | // 57 | 58 | 59 | ///////////////////////////////////////////////////////////////////////////// 60 | #endif // not APSTUDIO_INVOKED 61 | -------------------------------------------------------------------------------- /windows/OrientationWindows/OrientationWindows.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | true 6 | true 7 | true 8 | true 9 | {EF847B00-0D03-4611-93E3-40FFD0191998} 10 | OrientationWindows 11 | OrientationWindows 12 | en-US 13 | 14.0 14 | true 15 | Windows Store 16 | 10.0 17 | 10.0 18 | 10.0.17134.0 19 | 20 | 21 | 22 | $([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), 'node_modules\react-native-windows\package.json'))\node_modules\react-native-windows\ 23 | 24 | 25 | 26 | Debug 27 | ARM 28 | 29 | 30 | Debug 31 | ARM64 32 | 33 | 34 | Debug 35 | Win32 36 | 37 | 38 | Debug 39 | x64 40 | 41 | 42 | Release 43 | ARM 44 | 45 | 46 | Release 47 | ARM64 48 | 49 | 50 | Release 51 | Win32 52 | 53 | 54 | Release 55 | x64 56 | 57 | 58 | 59 | DynamicLibrary 60 | v140 61 | v141 62 | v142 63 | v143 64 | Unicode 65 | false 66 | 67 | 68 | true 69 | true 70 | 71 | 72 | false 73 | true 74 | false 75 | 76 | 77 | 78 | 79 | 80 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | Use 98 | pch.h 99 | $(IntDir)pch.pch 100 | Level4 101 | %(AdditionalOptions) /bigobj 102 | 103 | /DWINRT_NO_MAKE_DETECTION %(AdditionalOptions) 104 | 105 | 106 | _WINRT_DLL;WIN32_LEAN_AND_MEAN;WINRT_LEAN_AND_MEAN;%(PreprocessorDefinitions) 107 | $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) 108 | 109 | 110 | Console 111 | true 112 | OrientationWindows.def 113 | 114 | 115 | 116 | 117 | _DEBUG;%(PreprocessorDefinitions) 118 | 119 | 120 | 121 | 122 | NDEBUG;%(PreprocessorDefinitions) 123 | 124 | 125 | true 126 | true 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | Create 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | false 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | This project references targets in your node_modules\react-native-windows folder that are missing. The missing file is {0}. 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 179 | 180 | 181 | 182 | 183 | 184 | -------------------------------------------------------------------------------- /windows/OrientationWindows/OrientationWindows.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | accd3aa8-1ba0-4223-9bbe-0c431709210b 6 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms 7 | 8 | 9 | {926ab91d-31b4-48c3-b9a4-e681349f27f0} 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | Resources 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /windows/OrientationWindows/PropertySheet.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /windows/OrientationWindows/ReactPackageProvider.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "ReactPackageProvider.h" 3 | #include "ReactPackageProvider.g.cpp" 4 | 5 | #include 6 | #include "OrientationWindows.h" 7 | 8 | // NOTE: You must include the headers of your native modules here in 9 | // order for the AddAttributedModules call below to find them. 10 | 11 | namespace winrt::OrientationWindows::implementation 12 | { 13 | void ReactPackageProvider::CreatePackage(IReactPackageBuilder const& packageBuilder) noexcept 14 | { 15 | AddAttributedModules(packageBuilder); 16 | } 17 | } -------------------------------------------------------------------------------- /windows/OrientationWindows/ReactPackageProvider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ReactPackageProvider.g.h" 4 | 5 | using namespace winrt::Microsoft::ReactNative; 6 | 7 | namespace winrt::OrientationWindows::implementation 8 | { 9 | struct ReactPackageProvider : ReactPackageProviderT 10 | { 11 | ReactPackageProvider() = default; 12 | 13 | void CreatePackage(IReactPackageBuilder const& packageBuilder) noexcept; 14 | }; 15 | } 16 | 17 | namespace winrt::OrientationWindows::factory_implementation 18 | { 19 | struct ReactPackageProvider : ReactPackageProviderT {}; 20 | } 21 | -------------------------------------------------------------------------------- /windows/OrientationWindows/ReactPackageProvider.idl: -------------------------------------------------------------------------------- 1 | namespace OrientationWindows 2 | { 3 | [webhosthidden] 4 | [default_interface] 5 | runtimeclass ReactPackageProvider : Microsoft.ReactNative.IReactPackageProvider 6 | { 7 | ReactPackageProvider(); 8 | }; 9 | } 10 | -------------------------------------------------------------------------------- /windows/OrientationWindows/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /windows/OrientationWindows/pch.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | -------------------------------------------------------------------------------- /windows/OrientationWindows/pch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include "winrt/Windows.Graphics.Display.h" 6 | #include "winrt/Windows.UI.ViewManagement.h" 7 | #include "winrt/Windows.Devices.Sensors.h" 8 | #include "inspectable.h" -------------------------------------------------------------------------------- /windows/OrientationWindows/readme.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | C++/WinRT OrientationWindows Project Overview 3 | ======================================================================== 4 | 5 | This project demonstrates how to get started authoring Windows Runtime 6 | classes directly with standard C++, using the C++/WinRT SDK component 7 | to generate implementation headers from interface (IDL) files. The 8 | generated Windows Runtime component binary and WinMD files should then 9 | be bundled with the Universal Windows Platform (UWP) app consuming them. 10 | 11 | Steps: 12 | 1. Create an interface (IDL) file to define your Windows Runtime class, 13 | its default interface, and any other interfaces it implements. 14 | 2. Build the project once to generate module.g.cpp, module.h.cpp, and 15 | implementation templates under the "Generated Files" folder, as 16 | well as skeleton class definitions under "Generated Files\sources". 17 | 3. Use the skeleton class definitions for reference to implement your 18 | Windows Runtime classes. 19 | 20 | ======================================================================== 21 | Learn more about C++/WinRT here: 22 | http://aka.ms/cppwinrt/ 23 | ======================================================================== 24 | -------------------------------------------------------------------------------- /windows/OrientationWindows/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by OrientationWindows.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | --------------------------------------------------------------------------------