├── LICENSE.txt ├── RCTOrientationListener.h ├── RCTOrientationListener.m ├── RCTOrientationListener.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── RCTOrientationListener.xccheckout │ └── xcuserdata │ │ └── kenwheeler.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── kenwheeler.xcuserdatad │ └── xcschemes │ ├── RCTOrientationListener.xcscheme │ └── xcschememanagement.plist ├── README.md ├── android ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── walmartreact │ └── ReactOrientationListener │ ├── ReactOrientationListener.java │ └── ReactOrientationListenerModule.java ├── index.js ├── package.json └── react-native-orientation-listener.podspec /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Walmart Labs 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 13 | all 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 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /RCTOrientationListener.h: -------------------------------------------------------------------------------- 1 | // 2 | // RCTOrientationListener.h 3 | // 4 | // Created by Ken Wheeler on 9/9/15. 5 | // Copyright (c) 2015 Facebook. All rights reserved. 6 | // 7 | 8 | #import 9 | #import 10 | #import "RCTBridgeModule.h" 11 | #import "RCTBridge.h" 12 | #import "RCTEventDispatcher.h" 13 | 14 | @interface RCTOrientationListener : NSObject 15 | @end 16 | -------------------------------------------------------------------------------- /RCTOrientationListener.m: -------------------------------------------------------------------------------- 1 | // 2 | // RCTOrientationListener.m 3 | // 4 | // Created by Ken Wheeler on 9/9/15. 5 | // Copyright (c) 2015 Facebook. All rights reserved. 6 | // 7 | 8 | #import "RCTOrientationListener.h" 9 | #import "RCTBridge.h" 10 | 11 | @implementation RCTOrientationListener 12 | 13 | @synthesize bridge = _bridge; 14 | 15 | - (instancetype)init 16 | { 17 | if ((self = [super init])) { 18 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:@"UIDeviceOrientationDidChangeNotification" object:nil]; 19 | } 20 | return self; 21 | 22 | } 23 | 24 | - (void)dealloc 25 | { 26 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 27 | } 28 | 29 | - (void)deviceOrientationDidChange:(NSNotification *)notification 30 | { 31 | 32 | UIDevice *currentDevice = [UIDevice currentDevice]; 33 | UIDeviceOrientation orientation = [currentDevice orientation]; 34 | 35 | NSString *orientationStr; 36 | switch (orientation) { 37 | case UIDeviceOrientationPortrait: 38 | case UIDeviceOrientationPortraitUpsideDown: 39 | orientationStr = @"PORTRAIT"; 40 | break; 41 | case UIDeviceOrientationLandscapeLeft: 42 | case UIDeviceOrientationLandscapeRight: 43 | orientationStr = @"LANDSCAPE"; 44 | break; 45 | default: 46 | orientationStr = @"UNKNOWN"; 47 | break; 48 | } 49 | 50 | NSString *deviceStr = [currentDevice model]; 51 | 52 | [_bridge.eventDispatcher sendDeviceEventWithName:@"orientationDidChange" 53 | body:@{@"orientation": orientationStr,@"device": deviceStr}]; 54 | } 55 | 56 | RCT_EXPORT_MODULE(); 57 | 58 | RCT_EXPORT_METHOD(getOrientation:(RCTResponseSenderBlock)callback) 59 | { 60 | 61 | UIDevice *currentDevice = [UIDevice currentDevice]; 62 | UIDeviceOrientation orientation = [currentDevice orientation]; 63 | 64 | NSString *orientationStr; 65 | switch (orientation) { 66 | case UIDeviceOrientationPortrait: 67 | case UIDeviceOrientationPortraitUpsideDown: 68 | orientationStr = @"PORTRAIT"; 69 | break; 70 | case UIDeviceOrientationLandscapeLeft: 71 | case UIDeviceOrientationLandscapeRight: 72 | 73 | orientationStr = @"LANDSCAPE"; 74 | break; 75 | default: 76 | orientationStr = @"UNKNOWN"; 77 | break; 78 | } 79 | 80 | NSString *deviceStr = [currentDevice model]; 81 | 82 | NSArray *orientationArray = @[orientationStr, deviceStr]; 83 | callback(orientationArray); 84 | } 85 | 86 | @end 87 | -------------------------------------------------------------------------------- /RCTOrientationListener.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | B23A0C2D1BA7544300BD7916 /* RCTOrientationListener.m in Sources */ = {isa = PBXBuildFile; fileRef = B23A0C2C1BA7544300BD7916 /* RCTOrientationListener.m */; }; 11 | /* End PBXBuildFile section */ 12 | 13 | /* Begin PBXCopyFilesBuildPhase section */ 14 | B23A0BE81BA74C2500BD7916 /* CopyFiles */ = { 15 | isa = PBXCopyFilesBuildPhase; 16 | buildActionMask = 2147483647; 17 | dstPath = "include/$(PRODUCT_NAME)"; 18 | dstSubfolderSpec = 16; 19 | files = ( 20 | ); 21 | runOnlyForDeploymentPostprocessing = 0; 22 | }; 23 | /* End PBXCopyFilesBuildPhase section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | B23A0BEA1BA74C2500BD7916 /* libRCTOrientationListener.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTOrientationListener.a; sourceTree = BUILT_PRODUCTS_DIR; }; 27 | B23A0C2B1BA7543C00BD7916 /* RCTOrientationListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTOrientationListener.h; sourceTree = ""; }; 28 | B23A0C2C1BA7544300BD7916 /* RCTOrientationListener.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTOrientationListener.m; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | B23A0BE71BA74C2500BD7916 /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | B23A0BE11BA74C2500BD7916 = { 43 | isa = PBXGroup; 44 | children = ( 45 | B23A0C2B1BA7543C00BD7916 /* RCTOrientationListener.h */, 46 | B23A0C2C1BA7544300BD7916 /* RCTOrientationListener.m */, 47 | B23A0BEB1BA74C2500BD7916 /* Products */, 48 | ); 49 | sourceTree = ""; 50 | }; 51 | B23A0BEB1BA74C2500BD7916 /* Products */ = { 52 | isa = PBXGroup; 53 | children = ( 54 | B23A0BEA1BA74C2500BD7916 /* libRCTOrientationListener.a */, 55 | ); 56 | name = Products; 57 | sourceTree = ""; 58 | }; 59 | /* End PBXGroup section */ 60 | 61 | /* Begin PBXNativeTarget section */ 62 | B23A0BE91BA74C2500BD7916 /* RCTOrientationListener */ = { 63 | isa = PBXNativeTarget; 64 | buildConfigurationList = B23A0BFE1BA74C2500BD7916 /* Build configuration list for PBXNativeTarget "RCTOrientationListener" */; 65 | buildPhases = ( 66 | B23A0BE61BA74C2500BD7916 /* Sources */, 67 | B23A0BE71BA74C2500BD7916 /* Frameworks */, 68 | B23A0BE81BA74C2500BD7916 /* CopyFiles */, 69 | ); 70 | buildRules = ( 71 | ); 72 | dependencies = ( 73 | ); 74 | name = RCTOrientationListener; 75 | productName = RCTOrientationListener; 76 | productReference = B23A0BEA1BA74C2500BD7916 /* libRCTOrientationListener.a */; 77 | productType = "com.apple.product-type.library.static"; 78 | }; 79 | /* End PBXNativeTarget section */ 80 | 81 | /* Begin PBXProject section */ 82 | B23A0BE21BA74C2500BD7916 /* Project object */ = { 83 | isa = PBXProject; 84 | attributes = { 85 | LastUpgradeCheck = 0640; 86 | ORGANIZATIONNAME = "Ken Wheeler"; 87 | TargetAttributes = { 88 | B23A0BE91BA74C2500BD7916 = { 89 | CreatedOnToolsVersion = 6.4; 90 | }; 91 | }; 92 | }; 93 | buildConfigurationList = B23A0BE51BA74C2500BD7916 /* Build configuration list for PBXProject "RCTOrientationListener" */; 94 | compatibilityVersion = "Xcode 3.2"; 95 | developmentRegion = English; 96 | hasScannedForEncodings = 0; 97 | knownRegions = ( 98 | en, 99 | ); 100 | mainGroup = B23A0BE11BA74C2500BD7916; 101 | productRefGroup = B23A0BEB1BA74C2500BD7916 /* Products */; 102 | projectDirPath = ""; 103 | projectRoot = ""; 104 | targets = ( 105 | B23A0BE91BA74C2500BD7916 /* RCTOrientationListener */, 106 | ); 107 | }; 108 | /* End PBXProject section */ 109 | 110 | /* Begin PBXSourcesBuildPhase section */ 111 | B23A0BE61BA74C2500BD7916 /* Sources */ = { 112 | isa = PBXSourcesBuildPhase; 113 | buildActionMask = 2147483647; 114 | files = ( 115 | B23A0C2D1BA7544300BD7916 /* RCTOrientationListener.m in Sources */, 116 | ); 117 | runOnlyForDeploymentPostprocessing = 0; 118 | }; 119 | /* End PBXSourcesBuildPhase section */ 120 | 121 | /* Begin XCBuildConfiguration section */ 122 | B23A0BFC1BA74C2500BD7916 /* Debug */ = { 123 | isa = XCBuildConfiguration; 124 | buildSettings = { 125 | ALWAYS_SEARCH_USER_PATHS = NO; 126 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 127 | CLANG_CXX_LIBRARY = "libc++"; 128 | CLANG_ENABLE_MODULES = YES; 129 | CLANG_ENABLE_OBJC_ARC = YES; 130 | CLANG_WARN_BOOL_CONVERSION = YES; 131 | CLANG_WARN_CONSTANT_CONVERSION = YES; 132 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 133 | CLANG_WARN_EMPTY_BODY = YES; 134 | CLANG_WARN_ENUM_CONVERSION = YES; 135 | CLANG_WARN_INT_CONVERSION = YES; 136 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 137 | CLANG_WARN_UNREACHABLE_CODE = YES; 138 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 139 | COPY_PHASE_STRIP = NO; 140 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 141 | ENABLE_STRICT_OBJC_MSGSEND = YES; 142 | GCC_C_LANGUAGE_STANDARD = gnu99; 143 | GCC_DYNAMIC_NO_PIC = NO; 144 | GCC_NO_COMMON_BLOCKS = YES; 145 | GCC_OPTIMIZATION_LEVEL = 0; 146 | GCC_PREPROCESSOR_DEFINITIONS = ( 147 | "DEBUG=1", 148 | "$(inherited)", 149 | ); 150 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 151 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 152 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 153 | GCC_WARN_UNDECLARED_SELECTOR = YES; 154 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 155 | GCC_WARN_UNUSED_FUNCTION = YES; 156 | GCC_WARN_UNUSED_VARIABLE = YES; 157 | IPHONEOS_DEPLOYMENT_TARGET = 8.4; 158 | MTL_ENABLE_DEBUG_INFO = YES; 159 | ONLY_ACTIVE_ARCH = YES; 160 | SDKROOT = iphoneos; 161 | }; 162 | name = Debug; 163 | }; 164 | B23A0BFD1BA74C2500BD7916 /* Release */ = { 165 | isa = XCBuildConfiguration; 166 | buildSettings = { 167 | ALWAYS_SEARCH_USER_PATHS = NO; 168 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 169 | CLANG_CXX_LIBRARY = "libc++"; 170 | CLANG_ENABLE_MODULES = YES; 171 | CLANG_ENABLE_OBJC_ARC = YES; 172 | CLANG_WARN_BOOL_CONVERSION = YES; 173 | CLANG_WARN_CONSTANT_CONVERSION = YES; 174 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 175 | CLANG_WARN_EMPTY_BODY = YES; 176 | CLANG_WARN_ENUM_CONVERSION = YES; 177 | CLANG_WARN_INT_CONVERSION = YES; 178 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 179 | CLANG_WARN_UNREACHABLE_CODE = YES; 180 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 181 | COPY_PHASE_STRIP = NO; 182 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 183 | ENABLE_NS_ASSERTIONS = NO; 184 | ENABLE_STRICT_OBJC_MSGSEND = YES; 185 | GCC_C_LANGUAGE_STANDARD = gnu99; 186 | GCC_NO_COMMON_BLOCKS = YES; 187 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 188 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 189 | GCC_WARN_UNDECLARED_SELECTOR = YES; 190 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 191 | GCC_WARN_UNUSED_FUNCTION = YES; 192 | GCC_WARN_UNUSED_VARIABLE = YES; 193 | IPHONEOS_DEPLOYMENT_TARGET = 8.4; 194 | MTL_ENABLE_DEBUG_INFO = NO; 195 | SDKROOT = iphoneos; 196 | VALIDATE_PRODUCT = YES; 197 | }; 198 | name = Release; 199 | }; 200 | B23A0BFF1BA74C2500BD7916 /* Debug */ = { 201 | isa = XCBuildConfiguration; 202 | buildSettings = { 203 | HEADER_SEARCH_PATHS = ( 204 | "$(inherited)", 205 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 206 | "$(SRCROOT)/../../React/**", 207 | "$(SRCROOT)/../react-native/React/**", 208 | ); 209 | OTHER_LDFLAGS = "-ObjC"; 210 | PRODUCT_NAME = "$(TARGET_NAME)"; 211 | SKIP_INSTALL = YES; 212 | }; 213 | name = Debug; 214 | }; 215 | B23A0C001BA74C2500BD7916 /* Release */ = { 216 | isa = XCBuildConfiguration; 217 | buildSettings = { 218 | HEADER_SEARCH_PATHS = ( 219 | "$(inherited)", 220 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 221 | "$(SRCROOT)/../../React/**", 222 | "$(SRCROOT)/../react-native/React/**", 223 | ); 224 | OTHER_LDFLAGS = "-ObjC"; 225 | PRODUCT_NAME = "$(TARGET_NAME)"; 226 | SKIP_INSTALL = YES; 227 | }; 228 | name = Release; 229 | }; 230 | /* End XCBuildConfiguration section */ 231 | 232 | /* Begin XCConfigurationList section */ 233 | B23A0BE51BA74C2500BD7916 /* Build configuration list for PBXProject "RCTOrientationListener" */ = { 234 | isa = XCConfigurationList; 235 | buildConfigurations = ( 236 | B23A0BFC1BA74C2500BD7916 /* Debug */, 237 | B23A0BFD1BA74C2500BD7916 /* Release */, 238 | ); 239 | defaultConfigurationIsVisible = 0; 240 | defaultConfigurationName = Release; 241 | }; 242 | B23A0BFE1BA74C2500BD7916 /* Build configuration list for PBXNativeTarget "RCTOrientationListener" */ = { 243 | isa = XCConfigurationList; 244 | buildConfigurations = ( 245 | B23A0BFF1BA74C2500BD7916 /* Debug */, 246 | B23A0C001BA74C2500BD7916 /* Release */, 247 | ); 248 | defaultConfigurationIsVisible = 0; 249 | defaultConfigurationName = Release; 250 | }; 251 | /* End XCConfigurationList section */ 252 | }; 253 | rootObject = B23A0BE21BA74C2500BD7916 /* Project object */; 254 | } 255 | -------------------------------------------------------------------------------- /RCTOrientationListener.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /RCTOrientationListener.xcodeproj/project.xcworkspace/xcshareddata/RCTOrientationListener.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | A906C542-AD63-4B72-9374-5A2BFDC30BC3 9 | IDESourceControlProjectName 10 | RCTOrientationListener 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 312EAABBD5DC18F7B0B5D00ADBC45C6A13B9E004 14 | https://gecgithub01.walmart.com/react-native/wellness.git 15 | 16 | IDESourceControlProjectPath 17 | node_modules/react-native-orientation-listener/RCTOrientationListener.xcodeproj 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | 312EAABBD5DC18F7B0B5D00ADBC45C6A13B9E004 21 | ../../../.. 22 | 23 | IDESourceControlProjectURL 24 | https://gecgithub01.walmart.com/react-native/wellness.git 25 | IDESourceControlProjectVersion 26 | 111 27 | IDESourceControlProjectWCCIdentifier 28 | 312EAABBD5DC18F7B0B5D00ADBC45C6A13B9E004 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | 312EAABBD5DC18F7B0B5D00ADBC45C6A13B9E004 36 | IDESourceControlWCCName 37 | wellness 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /RCTOrientationListener.xcodeproj/project.xcworkspace/xcuserdata/kenwheeler.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/walmartlabs/react-native-orientation-listener/f276a2a6036e4dfcb4994ada717b2b0be7905090/RCTOrientationListener.xcodeproj/project.xcworkspace/xcuserdata/kenwheeler.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /RCTOrientationListener.xcodeproj/xcuserdata/kenwheeler.xcuserdatad/xcschemes/RCTOrientationListener.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 94 | 100 | 101 | 102 | 103 | 105 | 106 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /RCTOrientationListener.xcodeproj/xcuserdata/kenwheeler.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | RCTOrientationListener.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | B23A0BE91BA74C2500BD7916 16 | 17 | primary 18 | 19 | 20 | B23A0BF41BA74C2500BD7916 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | *** 2 | # NOTICE: 3 | 4 | ## This repository has been archived and is not supported. 5 | 6 | [![No Maintenance Intended](http://unmaintained.tech/badge.svg)](http://unmaintained.tech/) 7 | *** 8 | 9 | 10 | ## react-native-orientation-listener 11 | 12 | > A react-native library for obtaining current device orientation 13 | 14 | ###Getting Started 15 | 16 | - Run `npm install --save react-native-orientation-listener` 17 | 18 | ###IOS 19 | 20 | - Open your Xcode project, and select your project in the Project Navigator tab 21 | - Right click the `Libraries` folder and select "Add files to [your project]" 22 | - Add `RCTOrientationListener.xcodeproj` from your `node_modules` folder 23 | - Click your main project icon back in the Project Navigator to bring up preferences, and go to the `Build Phases` tab. 24 | - Click the `+` button underneath `Link Binary With Libraries` section. 25 | - Add `libRCTOrientationListener.a` 26 | 27 | ###Android 28 | - Open `/android/settings.gradle` 29 | - Replace `include ':app'` with: 30 | 31 | ``` 32 | include ':com.walmartreact.ReactOrientationListener', ':app' 33 | project(':com.walmartreact.ReactOrientationListener').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-orientation-listener/android') 34 | ``` 35 | - Open `android/app/build.gradle` 36 | - Add the following under `dependencies`: 37 | 38 | ``` 39 | compile project(':com.walmartreact.ReactOrientationListener') 40 | ``` 41 | - Open your `MainActivity.java` file under `android/src` 42 | - Import the lib using `import com.walmartreact.ReactOrientationListener.*;` 43 | - Add the following after `.addPackage(new MainReactPackage())`: 44 | 45 | ``` 46 | .addPackage(new ReactOrientationListener()) 47 | ``` 48 | 49 | ###Usage 50 | 51 | Import the library: 52 | 53 | ```javascript 54 | var Orientation = require('react-native-orientation-listener'); 55 | ``` 56 | 57 | ####getOrientation(callback) 58 | 59 | This method will return the current orientation and device string in the form of a callback: 60 | 61 | ```javascript 62 | componentDidMount(){ 63 | Orientation.getOrientation( 64 | (orientation, device) => { 65 | console.log(orientation, device); 66 | } 67 | ); 68 | } 69 | ``` 70 | 71 | ####addListener(callback) 72 | 73 | This method will add a listener that will call the callback anytime the device orienatation changes: 74 | 75 | ```javascript 76 | _setOrientation(data) { 77 | this.setState({ 78 | orientation: evt.orientation, 79 | device: evt.device 80 | }); 81 | }, 82 | componentDidMount(){ 83 | Orientation.addListener(this._setOrientation); 84 | } 85 | ``` 86 | 87 | ####removeListener(callback) 88 | 89 | This method removes the listener you added in componentDidMount: 90 | 91 | ```javascript 92 | componentWillUnmount() { 93 | Orientation.removeListener(this._setOrientation); 94 | } 95 | ``` 96 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.1" 6 | 7 | defaultConfig { 8 | minSdkVersion 16 9 | targetSdkVersion 22 10 | versionCode 1 11 | versionName "1.0" 12 | ndk { 13 | abiFilters "armeabi-v7a", "x86" 14 | } 15 | } 16 | } 17 | 18 | dependencies { 19 | compile 'com.facebook.react:react-native:0.11.+' 20 | } -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /android/src/main/java/com/walmartreact/ReactOrientationListener/ReactOrientationListener.java: -------------------------------------------------------------------------------- 1 | package com.walmartreact.ReactOrientationListener; 2 | 3 | import java.util.Arrays; 4 | import java.util.ArrayList; 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | import com.facebook.react.ReactPackage; 9 | import com.facebook.react.bridge.NativeModule; 10 | import com.facebook.react.bridge.ReactApplicationContext; 11 | import com.facebook.react.uimanager.ViewManager; 12 | import com.facebook.react.bridge.JavaScriptModule; 13 | 14 | public class ReactOrientationListener implements ReactPackage { 15 | 16 | @Override 17 | public List createNativeModules(ReactApplicationContext reactContext) { 18 | 19 | List modules = new ArrayList<>(); 20 | 21 | modules.add(new ReactOrientationListenerModule(reactContext)); 22 | 23 | return modules; 24 | } 25 | 26 | @Override 27 | public List> createJSModules() { 28 | return Collections.emptyList(); 29 | } 30 | 31 | @Override 32 | public List createViewManagers( 33 | ReactApplicationContext reactContext) { 34 | return Collections.emptyList(); 35 | } 36 | } -------------------------------------------------------------------------------- /android/src/main/java/com/walmartreact/ReactOrientationListener/ReactOrientationListenerModule.java: -------------------------------------------------------------------------------- 1 | package com.walmartreact.ReactOrientationListener; 2 | 3 | import javax.annotation.Nullable; 4 | 5 | import com.facebook.react.bridge.ReactApplicationContext; 6 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 7 | import com.facebook.react.bridge.ReactMethod; 8 | import com.facebook.react.bridge.Callback; 9 | import com.facebook.react.bridge.WritableNativeMap; 10 | import com.facebook.react.modules.core.DeviceEventManagerModule; 11 | 12 | import android.content.pm.PackageManager; 13 | import android.util.DisplayMetrics; 14 | import android.content.Context; 15 | import android.hardware.SensorManager; 16 | import android.view.OrientationEventListener; 17 | import android.os.Build; 18 | 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | public class ReactOrientationListenerModule extends ReactContextBaseJavaModule { 23 | 24 | ReactApplicationContext reactContext; 25 | OrientationEventListener mOrientationListener; 26 | 27 | public ReactOrientationListenerModule(ReactApplicationContext reactContext) { 28 | super(reactContext); 29 | this.reactContext = reactContext; 30 | final ReactApplicationContext thisContext = reactContext; 31 | 32 | mOrientationListener = new OrientationEventListener(reactContext, 33 | SensorManager.SENSOR_DELAY_NORMAL) { 34 | @Override 35 | public void onOrientationChanged(int orientation) { 36 | WritableNativeMap params = new WritableNativeMap(); 37 | String orientationValue = ""; 38 | if(orientation == 0) { 39 | orientationValue = "PORTRAIT"; 40 | } else { 41 | orientationValue = "LANDSCAPE"; 42 | } 43 | params.putString("orientation", orientationValue); 44 | params.putString("device", getDeviceName()); 45 | if (thisContext.hasActiveCatalystInstance()) { 46 | thisContext 47 | .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) 48 | .emit("orientationDidChange", params); 49 | } 50 | } 51 | }; 52 | 53 | if (mOrientationListener.canDetectOrientation() == true) { 54 | mOrientationListener.enable(); 55 | } else { 56 | mOrientationListener.disable(); 57 | } 58 | } 59 | 60 | public String getDeviceName() { 61 | String manufacturer = Build.MANUFACTURER; 62 | String model = Build.MODEL; 63 | if (model.startsWith(manufacturer)) { 64 | return capitalize(model); 65 | } else { 66 | return capitalize(manufacturer) + " " + model; 67 | } 68 | } 69 | 70 | private String capitalize(String s) { 71 | if (s == null || s.length() == 0) { 72 | return ""; 73 | } 74 | char first = s.charAt(0); 75 | if (Character.isUpperCase(first)) { 76 | return s; 77 | } else { 78 | return Character.toUpperCase(first) + s.substring(1); 79 | } 80 | } 81 | 82 | @Override 83 | public String getName() { 84 | return "OrientationListener"; 85 | } 86 | 87 | @Override 88 | public @Nullable Map getConstants() { 89 | HashMap constants = new HashMap(); 90 | PackageManager packageManager = this.reactContext.getPackageManager(); 91 | String packageName = this.reactContext.getPackageName(); 92 | return constants; 93 | } 94 | 95 | @ReactMethod 96 | public void getOrientation(Callback success) { 97 | WritableNativeMap data = new WritableNativeMap(); 98 | DisplayMetrics metrics = this.reactContext.getResources().getDisplayMetrics(); 99 | String orientation = ""; 100 | if(metrics.widthPixels < metrics.heightPixels){ 101 | orientation = "PORTRAIT"; 102 | }else { 103 | orientation = "LANDSCAPE"; 104 | } 105 | data.putString("orientation", orientation); 106 | data.putString("device", getDeviceName()); 107 | success.invoke(data); 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var React = require('react-native'); 4 | 5 | var { DeviceEventEmitter, NativeModules } = React; 6 | 7 | module.exports = { 8 | getOrientation: function(callback) { 9 | NativeModules.OrientationListener.getOrientation(callback); 10 | }, 11 | addListener: function(callback) { 12 | return DeviceEventEmitter.addListener( 13 | 'orientationDidChange', callback 14 | ); 15 | }, 16 | removeListener: function(listener) { 17 | DeviceEventEmitter.removeListener( 18 | 'orientationDidChange', listener 19 | ); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-orientation-listener", 3 | "version": "0.0.4", 4 | "description": "A react-native library for obtaining current device orientation", 5 | "main": "index.js", 6 | "keywords": [ 7 | "react-native", 8 | "orientation", 9 | "device orientation" 10 | ], 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/walmartreact/react-native-orientation-listener.git" 14 | }, 15 | "author": "Ken Wheeler", 16 | "license": "MIT", 17 | "peerDependencies": { 18 | "react-native": ">=0.5" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /react-native-orientation-listener.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "react-native-orientation-listener" 3 | s.version = "0.0.2" 4 | s.summary = " react-native library for obtaining current device orientation" 5 | s.requires_arc = true 6 | s.author = { 'Ken Wheeler' => 'ken@outlook.com' } 7 | s.license = 'MIT' 8 | s.homepage = 'https://github.com/walmartreact/react-native-orientation-listener' 9 | s.source = { :git => "https://github.com/walmartreact/react-native-orientation-listener.git" } 10 | s.platform = :ios, "7.0" 11 | s.dependency 'React' 12 | s.source_files = "*.{h,m}" 13 | s.preserve_paths = "*.js" 14 | end 15 | --------------------------------------------------------------------------------