├── .gitignore ├── CHANGELOG.md ├── Device.js ├── DeviceUtil.h ├── DeviceUtil.m ├── README.md └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | .DS_Store 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 1.0.1 2 | ----- 3 | 4 | Fix incorrect import of the Dimensions module [#20](https://github.com/GertjanReynaert/react-native-device/pull/20) 5 | Thx @RWOverdijk for this fix 6 | 7 | 1.0.0 8 | ----- 9 | 10 | Uses Native UIDevice Class 11 | 12 | + Model 13 | + Device Name 14 | + System Name 15 | + System Version 16 | 17 | 18 | 0.1.0 19 | ----- 20 | 21 | First version 22 | -------------------------------------------------------------------------------- /Device.js: -------------------------------------------------------------------------------- 1 | var { NativeModules, Dimensions } = require('react-native'); 2 | var DeviceUtil = NativeModules.DeviceUtil; 3 | 4 | class Device { 5 | constructor() { 6 | this.width = Dimensions.get('window').width; 7 | this.height = Dimensions.get('window').height; 8 | this.model = DeviceUtil.model; 9 | this.deviceName = DeviceUtil.name; 10 | this.systemName = DeviceUtil.systemName; 11 | this.systemVersion = DeviceUtil.systemVersion; 12 | this.deviceVersion = DeviceUtil.deviceVersion; 13 | } 14 | 15 | isIpad() { 16 | return this.model.indexOf('iPad') >= 0; 17 | } 18 | 19 | isIphone() { 20 | return this.model.indexOf('iPhone') >= 0; 21 | } 22 | } 23 | 24 | module.exports = new Device(); 25 | -------------------------------------------------------------------------------- /DeviceUtil.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface DeviceUtil : NSObject 4 | 5 | @end 6 | -------------------------------------------------------------------------------- /DeviceUtil.m: -------------------------------------------------------------------------------- 1 | #import "DeviceUtil.h" 2 | #import "RCTBridge.h" 3 | #import "RCTUtils.h" 4 | #import 5 | 6 | @implementation DeviceUtil 7 | 8 | RCT_EXPORT_MODULE(); 9 | 10 | @synthesize bridge = _bridge; 11 | 12 | - (NSDictionary *)constantsToExport { 13 | NSString *model = [[UIDevice currentDevice] model]; 14 | NSString *name = [[UIDevice currentDevice] name]; 15 | NSString *systemName = [[UIDevice currentDevice] systemName]; 16 | NSString *systemVersion = [[UIDevice currentDevice] systemVersion]; 17 | 18 | struct utsname systemInfo; 19 | uname(&systemInfo); 20 | NSString *deviceVersion = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding]; 21 | 22 | return @{ 23 | @"model" : (model), 24 | @"name" : (name), 25 | @"systemName" : (systemName), 26 | @"systemVersion" : (systemVersion), 27 | @"deviceVersion" : (deviceVersion) 28 | }; 29 | } 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React Native Device [deprecated] 2 | 3 | This project is no longer maintained. You can still use it as is, but bugs will no longer be fixed, features will no longer be implemented. An alternative to this package might be [react-native-device-info](https://github.com/rebeccahughes/react-native-device-info) 4 | 5 | ![NPM Stats](https://nodei.co/npm/react-native-device.png?downloads=true) 6 | 7 | A wrapper for the native [iOS UIDevice](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDevice_Class/index.html#//apple_ref/occ/cl/UIDevice) & [Android Build](http://developer.android.com/reference/android/os/Build.html) class allowing you to access device properties and screen dimensions. **Currently only for React Native iOS, [Android support](https://github.com/GertjanReynaert/react-native-device/issues/16) in progress.** 8 | 9 | ## Installation (iOS) 10 | 11 | First install the package to your project from NPM... 12 | 13 | ``` 14 | npm install react-native-device --save 15 | ``` 16 | 17 | Then within the package folder just add both the `.h` and `.m` classes to your project... 18 | 19 | 20 | 21 | ## Methods 22 | 23 | ```javascript 24 | Device.isIpad() 25 | ``` 26 | 27 | The device model is of type iPad 28 | 29 | ```javascript 30 | Device.isIphone() 31 | ``` 32 | 33 | The device model is of type iPhone 34 | 35 | ## Properties 36 | 37 | ```javascript 38 | Device.model 39 | ``` 40 | 41 | The device model, such as `iPhone` or `iPad` 42 | 43 | ```javascript 44 | Device.deviceName 45 | ``` 46 | 47 | The device name, such as `John Smith's iPhone` 48 | 49 | ```javascript 50 | Device.systemName 51 | ``` 52 | 53 | The device OS name, such as `iPhone OS` 54 | 55 | ```javascript 56 | Device.systemVersion 57 | ``` 58 | 59 | The device OS version, such as `8.4` 60 | ```javascript 61 | Device.deviceVersion 62 | ``` 63 | 64 | The specific device version, such as `iPhone 4S` or `iPhone 6` - [All model options](https://gist.github.com/kkjdaniel/652cf598ae0ac298a50b) 65 | 66 | ## Example 67 | 68 | ```javascript 69 | 'use strict'; 70 | 71 | var Device = require('react-native-device'); 72 | 73 | var ExampleApp = React.createClass({ 74 | render: function() { 75 | if (Device.isIpad()) { 76 | // return iPad layout 77 | } else { 78 | // return iPhone layout 79 | } 80 | } 81 | }); 82 | ``` 83 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-device", 3 | "version": "1.0.1", 4 | "description": "UIDevice wrapper for React Native", 5 | "main": "Device.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/GertjanReynaert/react-native-device" 12 | }, 13 | "keywords": [ 14 | "react-component", 15 | "react-native", 16 | "ios", 17 | "device", 18 | "detection", 19 | "UIDevice", 20 | "model", 21 | "name" 22 | ], 23 | "author": "Gertjan Reynaert", 24 | "license": "MIT" 25 | } 26 | --------------------------------------------------------------------------------