├── .gitignore ├── Example ├── .flowconfig ├── .gitignore ├── .watchmanconfig ├── android │ ├── app │ │ ├── build.gradle │ │ ├── proguard-rules.pro │ │ ├── react.gradle │ │ └── src │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── MainActivity.java │ │ │ └── res │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ │ └── values │ │ │ ├── strings.xml │ │ │ └── styles.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── index.android.js └── package.json ├── LICENSE.md ├── README.md ├── android ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── ca │ └── jaysoo │ └── extradimensions │ ├── ExtraDimensionsModule.java │ └── ExtraDimensionsPackage.java ├── demo.png ├── index.d.ts ├── index.js ├── package.json └── react-native.config.js /.gitignore: -------------------------------------------------------------------------------- 1 | lib/ 2 | node_modules/ 3 | npm-debug.log 4 | .idea/ 5 | android/build 6 | *.iml 7 | -------------------------------------------------------------------------------- /Example/.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | 3 | # We fork some components by platform. 4 | .*/*.web.js 5 | .*/*.android.js 6 | 7 | # Some modules have their own node_modules with overlap 8 | .*/node_modules/node-haste/.* 9 | 10 | # Ugh 11 | .*/node_modules/babel.* 12 | .*/node_modules/babylon.* 13 | .*/node_modules/invariant.* 14 | 15 | # Ignore react and fbjs where there are overlaps, but don't ignore 16 | # anything that react-native relies on 17 | .*/node_modules/fbjs-haste/.*/__tests__/.* 18 | .*/node_modules/fbjs-haste/__forks__/Map.js 19 | .*/node_modules/fbjs-haste/__forks__/Promise.js 20 | .*/node_modules/fbjs-haste/__forks__/fetch.js 21 | .*/node_modules/fbjs-haste/core/ExecutionEnvironment.js 22 | .*/node_modules/fbjs-haste/core/isEmpty.js 23 | .*/node_modules/fbjs-haste/crypto/crc32.js 24 | .*/node_modules/fbjs-haste/stubs/ErrorUtils.js 25 | .*/node_modules/react-haste/React.js 26 | .*/node_modules/react-haste/renderers/dom/ReactDOM.js 27 | .*/node_modules/react-haste/renderers/shared/event/eventPlugins/ResponderEventPlugin.js 28 | 29 | # Ignore commoner tests 30 | .*/node_modules/commoner/test/.* 31 | 32 | # See https://github.com/facebook/flow/issues/442 33 | .*/react-tools/node_modules/commoner/lib/reader.js 34 | 35 | # Ignore jest 36 | .*/node_modules/jest-cli/.* 37 | 38 | # Ignore Website 39 | .*/website/.* 40 | 41 | [include] 42 | 43 | [libs] 44 | node_modules/react-native/Libraries/react-native/react-native-interface.js 45 | 46 | [options] 47 | module.system=haste 48 | 49 | munge_underscores=true 50 | 51 | module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub' 52 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.png$' -> 'RelativeImageStub' 53 | 54 | suppress_type=$FlowIssue 55 | suppress_type=$FlowFixMe 56 | suppress_type=$FixMe 57 | 58 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) 59 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)? #[0-9]+ 60 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 61 | 62 | [version] 63 | 0.19.0 64 | -------------------------------------------------------------------------------- /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 | project.xcworkspace 24 | 25 | # Android/IJ 26 | # 27 | .idea 28 | .gradle 29 | local.properties 30 | 31 | # node.js 32 | # 33 | node_modules/ 34 | npm-debug.log 35 | -------------------------------------------------------------------------------- /Example/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /Example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | 3 | /** 4 | * The react.gradle file registers two tasks: bundleDebugJsAndAssets and bundleReleaseJsAndAssets. 5 | * These basically call `react-native bundle` with the correct arguments during the Android build 6 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the 7 | * bundle directly from the development server. Below you can see all the possible configurations 8 | * and their defaults. If you decide to add a configuration block, make sure to add it before the 9 | * `apply from: "react.gradle"` line. 10 | * 11 | * project.ext.react = [ 12 | * // the name of the generated asset file containing your JS bundle 13 | * bundleAssetName: "index.android.bundle", 14 | * 15 | * // the entry file for bundle generation 16 | * entryFile: "index.android.js", 17 | * 18 | * // whether to bundle JS and assets in debug mode 19 | * bundleInDebug: false, 20 | * 21 | * // whether to bundle JS and assets in release mode 22 | * bundleInRelease: true, 23 | * 24 | * // the root of your project, i.e. where "package.json" lives 25 | * root: "../../", 26 | * 27 | * // where to put the JS bundle asset in debug mode 28 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", 29 | * 30 | * // where to put the JS bundle asset in release mode 31 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release", 32 | * 33 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 34 | * // require('./image.png')), in debug mode 35 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", 36 | * 37 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 38 | * // require('./image.png')), in release mode 39 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", 40 | * 41 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means 42 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to 43 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle 44 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ 45 | * // for example, you might want to remove it from here. 46 | * inputExcludes: ["android/**", "ios/**"] 47 | * ] 48 | */ 49 | 50 | apply from: "react.gradle" 51 | 52 | android { 53 | compileSdkVersion 23 54 | buildToolsVersion "23.0.1" 55 | 56 | defaultConfig { 57 | applicationId "com.example" 58 | minSdkVersion 16 59 | targetSdkVersion 22 60 | versionCode 1 61 | versionName "1.0" 62 | ndk { 63 | abiFilters "armeabi-v7a", "x86" 64 | } 65 | } 66 | buildTypes { 67 | release { 68 | minifyEnabled false // Set this to true to enable Proguard 69 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 70 | } 71 | } 72 | } 73 | 74 | dependencies { 75 | compile fileTree(dir: "libs", include: ["*.jar"]) 76 | compile "com.android.support:appcompat-v7:23.0.1" 77 | compile "com.facebook.react:react-native:0.17.+" 78 | compile project(':ExtraDimensions') 79 | } 80 | -------------------------------------------------------------------------------- /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 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Disabling obfuscation is useful if you collect stack traces from production crashes 20 | # (unless you are using a system that supports de-obfuscate the stack traces). 21 | -dontobfuscate 22 | 23 | # React Native 24 | 25 | # Keep our interfaces so they can be used by other ProGuard rules. 26 | # See http://sourceforge.net/p/proguard/bugs/466/ 27 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip 28 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters 29 | 30 | # Do not strip any method/class that is annotated with @DoNotStrip 31 | -keep @com.facebook.proguard.annotations.DoNotStrip class * 32 | -keepclassmembers class * { 33 | @com.facebook.proguard.annotations.DoNotStrip *; 34 | } 35 | 36 | -keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * { 37 | void set*(***); 38 | *** get*(); 39 | } 40 | 41 | -keep class * extends com.facebook.react.bridge.JavaScriptModule { *; } 42 | -keep class * extends com.facebook.react.bridge.NativeModule { *; } 43 | -keepclassmembers class * { @com.facebook.react.uimanager.UIProp ; } 44 | -keepclassmembers class * { @com.facebook.react.uimanager.ReactProp ; } 45 | -keepclassmembers class * { @com.facebook.react.uimanager.ReactPropGroup ; } 46 | 47 | # okhttp 48 | 49 | -keepattributes Signature 50 | -keepattributes *Annotation* 51 | -keep class com.squareup.okhttp.** { *; } 52 | -keep interface com.squareup.okhttp.** { *; } 53 | -dontwarn com.squareup.okhttp.** 54 | 55 | # okio 56 | 57 | -keep class sun.misc.Unsafe { *; } 58 | -dontwarn java.nio.file.* 59 | -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement 60 | -dontwarn okio.** 61 | -------------------------------------------------------------------------------- /Example/android/app/react.gradle: -------------------------------------------------------------------------------- 1 | import org.apache.tools.ant.taskdefs.condition.Os 2 | 3 | def config = project.hasProperty("react") ? project.react : []; 4 | 5 | def bundleAssetName = config.bundleAssetName ?: "index.android.bundle" 6 | def entryFile = config.entryFile ?: "index.android.js" 7 | 8 | // because elvis operator 9 | def elvisFile(thing) { 10 | return thing ? file(thing) : null; 11 | } 12 | 13 | def reactRoot = elvisFile(config.root) ?: file("../../") 14 | def jsBundleDirDebug = elvisFile(config.jsBundleDirDebug) ?: 15 | file("$buildDir/intermediates/assets/debug") 16 | def jsBundleDirRelease = elvisFile(config.jsBundleDirRelease) ?: 17 | file("$buildDir/intermediates/assets/release") 18 | def resourcesDirDebug = elvisFile(config.resourcesDirDebug) ?: 19 | file("$buildDir/intermediates/res/merged/debug") 20 | def resourcesDirRelease = elvisFile(config.resourcesDirRelease) ?: 21 | file("$buildDir/intermediates/res/merged/release") 22 | def inputExcludes = config.inputExcludes ?: ["android/**", "ios/**"] 23 | 24 | def jsBundleFileDebug = file("$jsBundleDirDebug/$bundleAssetName") 25 | def jsBundleFileRelease = file("$jsBundleDirRelease/$bundleAssetName") 26 | 27 | task bundleDebugJsAndAssets(type: Exec) { 28 | // create dirs if they are not there (e.g. the "clean" task just ran) 29 | doFirst { 30 | jsBundleDirDebug.mkdirs() 31 | resourcesDirDebug.mkdirs() 32 | } 33 | 34 | // set up inputs and outputs so gradle can cache the result 35 | inputs.files fileTree(dir: reactRoot, excludes: inputExcludes) 36 | outputs.dir jsBundleDirDebug 37 | outputs.dir resourcesDirDebug 38 | 39 | // set up the call to the react-native cli 40 | workingDir reactRoot 41 | if (Os.isFamily(Os.FAMILY_WINDOWS)) { 42 | commandLine "cmd", "/c", "react-native", "bundle", "--platform", "android", "--dev", "true", "--entry-file", 43 | entryFile, "--bundle-output", jsBundleFileDebug, "--assets-dest", resourcesDirDebug 44 | } else { 45 | commandLine "react-native", "bundle", "--platform", "android", "--dev", "true", "--entry-file", 46 | entryFile, "--bundle-output", jsBundleFileDebug, "--assets-dest", resourcesDirDebug 47 | } 48 | 49 | enabled config.bundleInDebug ?: false 50 | } 51 | 52 | task bundleReleaseJsAndAssets(type: Exec) { 53 | // create dirs if they are not there (e.g. the "clean" task just ran) 54 | doFirst { 55 | jsBundleDirRelease.mkdirs() 56 | resourcesDirRelease.mkdirs() 57 | } 58 | 59 | // set up inputs and outputs so gradle can cache the result 60 | inputs.files fileTree(dir: reactRoot, excludes: inputExcludes) 61 | outputs.dir jsBundleDirRelease 62 | outputs.dir resourcesDirRelease 63 | 64 | // set up the call to the react-native cli 65 | workingDir reactRoot 66 | if (Os.isFamily(Os.FAMILY_WINDOWS)) { 67 | commandLine "cmd","/c", "react-native", "bundle", "--platform", "android", "--dev", "false", "--entry-file", 68 | entryFile, "--bundle-output", jsBundleFileRelease, "--assets-dest", resourcesDirRelease 69 | } else { 70 | commandLine "react-native", "bundle", "--platform", "android", "--dev", "false", "--entry-file", 71 | entryFile, "--bundle-output", jsBundleFileRelease, "--assets-dest", resourcesDirRelease 72 | } 73 | 74 | enabled config.bundleInRelease ?: true 75 | } 76 | 77 | gradle.projectsEvaluated { 78 | // hook bundleDebugJsAndAssets into the android build process 79 | bundleDebugJsAndAssets.dependsOn mergeDebugResources 80 | bundleDebugJsAndAssets.dependsOn mergeDebugAssets 81 | processDebugResources.dependsOn bundleDebugJsAndAssets 82 | 83 | // hook bundleReleaseJsAndAssets into the android build process 84 | bundleReleaseJsAndAssets.dependsOn mergeReleaseResources 85 | bundleReleaseJsAndAssets.dependsOn mergeReleaseAssets 86 | processReleaseResources.dependsOn bundleReleaseJsAndAssets 87 | } 88 | -------------------------------------------------------------------------------- /Example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 11 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Example/android/app/src/main/java/com/example/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.view.KeyEvent; 6 | 7 | import com.facebook.react.LifecycleState; 8 | import com.facebook.react.ReactInstanceManager; 9 | import com.facebook.react.ReactRootView; 10 | import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler; 11 | import com.facebook.react.shell.MainReactPackage; 12 | import com.facebook.soloader.SoLoader; 13 | 14 | import ca.jaysoo.extradimensions.ExtraDimensionsPackage; // <---- Add here 15 | 16 | public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler { 17 | 18 | private ReactInstanceManager mReactInstanceManager; 19 | private ReactRootView mReactRootView; 20 | 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | mReactRootView = new ReactRootView(this); 25 | 26 | mReactInstanceManager = ReactInstanceManager.builder() 27 | .setApplication(getApplication()) 28 | .setBundleAssetName("index.android.bundle") 29 | .setJSMainModuleName("index.android") 30 | .addPackage(new MainReactPackage()) 31 | .addPackage(new ExtraDimensionsPackage(this)) 32 | .setUseDeveloperSupport(BuildConfig.DEBUG) 33 | .setInitialLifecycleState(LifecycleState.RESUMED) 34 | .build(); 35 | 36 | mReactRootView.startReactApplication(mReactInstanceManager, "Example", null); 37 | 38 | setContentView(mReactRootView); 39 | } 40 | 41 | @Override 42 | public boolean onKeyUp(int keyCode, KeyEvent event) { 43 | if (keyCode == KeyEvent.KEYCODE_MENU && mReactInstanceManager != null) { 44 | mReactInstanceManager.showDevOptionsDialog(); 45 | return true; 46 | } 47 | return super.onKeyUp(keyCode, event); 48 | } 49 | 50 | @Override 51 | public void onBackPressed() { 52 | if (mReactInstanceManager != null) { 53 | mReactInstanceManager.onBackPressed(); 54 | } else { 55 | super.onBackPressed(); 56 | } 57 | } 58 | 59 | @Override 60 | public void invokeDefaultOnBackPressed() { 61 | super.onBackPressed(); 62 | } 63 | 64 | @Override 65 | protected void onPause() { 66 | super.onPause(); 67 | 68 | if (mReactInstanceManager != null) { 69 | mReactInstanceManager.onPause(); 70 | } 71 | } 72 | 73 | @Override 74 | protected void onResume() { 75 | super.onResume(); 76 | 77 | if (mReactInstanceManager != null) { 78 | mReactInstanceManager.onResume(this, this); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sunhat/react-native-extra-dimensions-android/940ffe2c76d59b6c7c66da04a956c044127949ba/Example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sunhat/react-native-extra-dimensions-android/940ffe2c76d59b6c7c66da04a956c044127949ba/Example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sunhat/react-native-extra-dimensions-android/940ffe2c76d59b6c7c66da04a956c044127949ba/Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sunhat/react-native-extra-dimensions-android/940ffe2c76d59b6c7c66da04a956c044127949ba/Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.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 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /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 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:1.3.1' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | mavenLocal() 18 | jcenter() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /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 | android.useDeprecatedNdk=true 21 | -------------------------------------------------------------------------------- /Example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sunhat/react-native-extra-dimensions-android/940ffe2c76d59b6c7c66da04a956c044127949ba/Example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip 6 | -------------------------------------------------------------------------------- /Example/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 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 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /Example/android/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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 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 Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /Example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Example' 2 | 3 | include ':ExtraDimensions', ':app' 4 | project(':ExtraDimensions').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-extra-dimensions-android/android') 5 | -------------------------------------------------------------------------------- /Example/index.android.js: -------------------------------------------------------------------------------- 1 | 2 | 'use strict'; 3 | 4 | const React = require('react-native'); 5 | const { 6 | AppRegistry, 7 | Dimensions, 8 | Text, 9 | View 10 | } = React; 11 | 12 | const ExtraDimensions = require('react-native-extra-dimensions-android'); 13 | 14 | const window = Dimensions.get('window'); 15 | 16 | const Example = React.createClass({ 17 | render() { 18 | return ( 19 | 20 | 21 | STATUS_BAR_HEIGHT ({ExtraDimensions.get('STATUS_BAR_HEIGHT')}) 22 | 23 | 24 | REAL_WINDOW_HEIGHT ({ExtraDimensions.get('REAL_WINDOW_HEIGHT')}) 25 | REAL_WINDOW_WIDTH ({ExtraDimensions.get('REAL_WINDOW_WIDTH')}) 26 | 27 | 28 | SOFT_MENU_BAR_HEIGHT ({ExtraDimensions.get('SOFT_MENU_BAR_HEIGHT')}) 29 | 30 | 31 | ); 32 | } 33 | }); 34 | 35 | AppRegistry.registerComponent('Example', () => Example); 36 | -------------------------------------------------------------------------------- /Example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Example", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "start": "react-native start" 7 | }, 8 | "dependencies": { 9 | "react-native": "^0.17.0", 10 | "react-native-extra-dimensions-android": "../" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | ## ISC License 2 | 3 | Copyright (c) 2015, Jack Hsu 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ### Notice 3 | This project is dead. As a React Native developer, I do not use this package. It is not needed. 4 | 5 | ## ExtraDimensions 6 | 7 | This module allows you to access additional display metrics on Android devices. (RN 0.57.0+) 8 | 9 | - Actual width and height of the screen (including elements such as soft menu bar) 10 | - Soft menu height 11 | - Status bar height 12 | - Smart bar height (MeiZu) 13 | 14 | 15 | ### Why? 16 | 17 | There is currently a bug in React Native where [`Dimensions.get('window').height` sometimes returns 18 | the wrong value](https://github.com/facebook/react-native/issues/4934). 19 | 20 | Also, some apps may want to set the background of status bar and soft menu bar to transparent, thus the top-level 21 | view needs to fill up the real screen size. 22 | 23 | ### Installation 24 | 25 | 1. Install with npm 26 | ``` 27 | npm install react-native-extra-dimensions-android --save 28 | ``` 29 | 30 | 2. linking 31 | 32 | ``` 33 | react-native link react-native-extra-dimensions-android 34 | ``` 35 | 36 | 2b. You may have to register the module (in android/app/src/main/java/com/YOUR-PROJECT-NAME/MainApplication.java) 37 | `react-native link` should automatically do the following for you. If it doesn't, you might have to add it yourself. 38 | 39 | ``` 40 | import ca.jaysoo.extradimensions.ExtraDimensionsPackage; // <--- import 41 | 42 | public class MainApplication extends Application implements ReactApplication { 43 | ...... 44 | protected List getPackages() { 45 | return Arrays.asList( 46 | new MainReactPackage(), 47 | new ExtraDimensionsPackage() // <--- add here 48 | ); 49 | } 50 | ...... 51 | } 52 | ``` 53 | 3. As this is a package with Java, you'll need to rebuild the project. 54 | 55 | e.g. `react-native run-android` 56 | 57 | 4. Whenever you want to use it within React Native code now you can: 58 | 59 | `var ExtraDimensions = require('react-native-extra-dimensions-android');` 60 | 61 | Or, if you are using ES6 62 | 63 | `import ExtraDimensions from 'react-native-extra-dimensions-android';` 64 | 65 | ### Demo 66 | 67 | ![](./demo.png) 68 | 69 | ### API 70 | 71 | `ExtraDimensions.get(dimension: string)` that takes in a dimension name, and returns its value as a `number`. 72 | 73 | Supported dimensions are: 74 | 75 | - `REAL_WINDOW_HEIGHT` - Actual height of screen including system decor elements 76 | - `REAL_WINDOW_WIDTH` - Actual width of screen including system decor elements 77 | - `STATUS_BAR_HEIGHT` - Height of the status bar 78 | - `SOFT_MENU_BAR_HEIGHT` - Height of the soft menu bar (supported on most new Android devices) 79 | - `SMART_BAR_HEIGHT` - Height of the MeiZu's device smart bar 80 | 81 | Alternatively, there are methods for each constant, to fulfill autocomplete in your IDE 82 | 83 | `ExtraDimensions.getRealWindowHeight()` 84 | 85 | `ExtraDimensions.getRealWindowWidth()` 86 | 87 | `ExtraDimensions.getStatusBarHeight()` 88 | 89 | `ExtraDimensions.getSoftMenuBarHeight()` 90 | 91 | `ExtraDimensions.getSmartBarHeight()` 92 | 93 | `ExtraDimensions.isSoftMenuBarEnabled()` 94 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | def safeExtGet(prop, fallback) { 2 | rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback 3 | } 4 | 5 | apply plugin: 'com.android.library' 6 | 7 | def DEFAULT_COMPILE_SDK_VERSION = 27 8 | def DEFAULT_BUILD_TOOLS_VERSION = "27.0.3" 9 | def DEFAULT_TARGET_SDK_VERSION = 26 10 | def DEFAULT_SUPPORT_LIB_VERSION = "27.0.2" 11 | 12 | android { 13 | compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION 14 | buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION 15 | 16 | defaultConfig { 17 | minSdkVersion 16 18 | targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION 19 | versionCode 1 20 | versionName "1.0" 21 | ndk { 22 | abiFilters "armeabi-v7a", "x86" 23 | } 24 | } 25 | } 26 | 27 | dependencies { 28 | implementation 'com.facebook.react:react-native:+' 29 | } 30 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /android/src/main/java/ca/jaysoo/extradimensions/ExtraDimensionsModule.java: -------------------------------------------------------------------------------- 1 | package ca.jaysoo.extradimensions; 2 | 3 | import java.lang.Math; 4 | import java.lang.reflect.InvocationTargetException; 5 | 6 | import android.content.Context; 7 | import android.os.Build; 8 | import android.util.DisplayMetrics; 9 | import android.view.Display; 10 | import android.provider.Settings; 11 | import android.content.res.Resources; 12 | import android.view.WindowManager; 13 | import android.view.ViewConfiguration; 14 | 15 | import com.facebook.react.bridge.ReactApplicationContext; 16 | import com.facebook.react.bridge.LifecycleEventListener; 17 | import com.facebook.react.bridge.ReactContext; 18 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 19 | 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | 23 | import java.lang.reflect.Field; 24 | 25 | public class ExtraDimensionsModule extends ReactContextBaseJavaModule implements LifecycleEventListener { 26 | 27 | private ReactContext mReactContext; 28 | 29 | public ExtraDimensionsModule(ReactApplicationContext reactContext) { 30 | super(reactContext); 31 | mReactContext = reactContext; 32 | mReactContext.addLifecycleEventListener(this); 33 | } 34 | 35 | @Override 36 | public String getName() { 37 | return "ExtraDimensions"; 38 | } 39 | 40 | @Override 41 | public void onHostDestroy() { 42 | 43 | } 44 | 45 | @Override 46 | public void onHostPause() { 47 | 48 | } 49 | 50 | @Override 51 | public void onHostResume() { 52 | 53 | } 54 | 55 | @Override 56 | public Map getConstants() { 57 | final Map constants = new HashMap<>(); 58 | 59 | final Context ctx = getReactApplicationContext(); 60 | final DisplayMetrics metrics = ctx.getResources().getDisplayMetrics(); 61 | 62 | // Get the real display metrics if we are using API level 17 or higher. 63 | // The real metrics include system decor elements (e.g. soft menu bar). 64 | // 65 | // See: http://developer.android.com/reference/android/view/Display.html#getRealMetrics(android.util.DisplayMetrics) 66 | if (Build.VERSION.SDK_INT >= 17) { 67 | Display display = ((WindowManager) mReactContext.getSystemService(Context.WINDOW_SERVICE)) 68 | .getDefaultDisplay(); 69 | try { 70 | Display.class.getMethod("getRealMetrics", DisplayMetrics.class).invoke(display, metrics); 71 | } catch (InvocationTargetException e) { 72 | } catch (IllegalAccessException e) { 73 | } catch (NoSuchMethodException e) { 74 | } 75 | } 76 | 77 | constants.put("REAL_WINDOW_HEIGHT", getRealHeight(metrics)); 78 | constants.put("REAL_WINDOW_WIDTH", getRealWidth(metrics)); 79 | constants.put("STATUS_BAR_HEIGHT", getStatusBarHeight(metrics)); 80 | constants.put("SOFT_MENU_BAR_HEIGHT", getSoftMenuBarHeight(metrics)); 81 | constants.put("SMART_BAR_HEIGHT", getSmartBarHeight(metrics)); 82 | constants.put("SOFT_MENU_BAR_ENABLED", hasPermanentMenuKey()); 83 | 84 | return constants; 85 | } 86 | 87 | private boolean hasPermanentMenuKey() { 88 | final Context ctx = getReactApplicationContext(); 89 | int id = ctx.getResources().getIdentifier("config_showNavigationBar", "bool", "android"); 90 | return !(id > 0 && ctx.getResources().getBoolean(id)); 91 | } 92 | 93 | private float getStatusBarHeight(DisplayMetrics metrics) { 94 | final Context ctx = getReactApplicationContext(); 95 | final int heightResId = ctx.getResources().getIdentifier("status_bar_height", "dimen", "android"); 96 | return 97 | heightResId > 0 98 | ? ctx.getResources().getDimensionPixelSize(heightResId) / metrics.density 99 | : 0; 100 | } 101 | 102 | private float getSoftMenuBarHeight(DisplayMetrics metrics) { 103 | if(hasPermanentMenuKey()) { 104 | return 0; 105 | } 106 | final Context ctx = getReactApplicationContext(); 107 | final int heightResId = ctx.getResources().getIdentifier("navigation_bar_height", "dimen", "android"); 108 | return 109 | heightResId > 0 110 | ? ctx.getResources().getDimensionPixelSize(heightResId) / metrics.density 111 | : 0; 112 | } 113 | 114 | private float getRealHeight(DisplayMetrics metrics) { 115 | return metrics.heightPixels / metrics.density; 116 | } 117 | 118 | private float getRealWidth(DisplayMetrics metrics) { 119 | return metrics.widthPixels / metrics.density; 120 | } 121 | 122 | // 获取魅族SmartBar高度 123 | private float getSmartBarHeight(DisplayMetrics metrics) { 124 | final Context context = getReactApplicationContext(); 125 | final boolean isMeiZu = Build.MANUFACTURER.equals("Meizu"); 126 | 127 | final boolean autoHideSmartBar = Settings.System.getInt(context.getContentResolver(), 128 | "mz_smartbar_auto_hide", 0) == 1; 129 | 130 | if (!isMeiZu || autoHideSmartBar) { 131 | return 0; 132 | } 133 | try { 134 | Class c = Class.forName("com.android.internal.R$dimen"); 135 | Object obj = c.newInstance(); 136 | Field field = c.getField("mz_action_button_min_height"); 137 | int height = Integer.parseInt(field.get(obj).toString()); 138 | return context.getResources().getDimensionPixelSize(height) / metrics.density; 139 | } catch (Throwable e) { // 不自动隐藏smartbar同时又没有smartbar高度字段供访问,取系统navigationbar的高度 140 | return getNormalNavigationBarHeight(context) / metrics.density; 141 | } 142 | //return getNormalNavigationBarHeight(context) / metrics.density; 143 | } 144 | 145 | protected static float getNormalNavigationBarHeight(final Context ctx) { 146 | try { 147 | final Resources res = ctx.getResources(); 148 | int rid = res.getIdentifier("config_showNavigationBar", "bool", "android"); 149 | if (rid > 0) { 150 | boolean flag = res.getBoolean(rid); 151 | if (flag) { 152 | int resourceId = res.getIdentifier("navigation_bar_height", "dimen", "android"); 153 | if (resourceId > 0) { 154 | return res.getDimensionPixelSize(resourceId); 155 | } 156 | } 157 | } 158 | } catch (Throwable e) { 159 | return 0; 160 | } 161 | return 0; 162 | } 163 | } -------------------------------------------------------------------------------- /android/src/main/java/ca/jaysoo/extradimensions/ExtraDimensionsPackage.java: -------------------------------------------------------------------------------- 1 | package ca.jaysoo.extradimensions; 2 | 3 | import com.facebook.react.ReactPackage; 4 | import com.facebook.react.bridge.JavaScriptModule; 5 | import com.facebook.react.bridge.NativeModule; 6 | import com.facebook.react.bridge.ReactApplicationContext; 7 | import com.facebook.react.uimanager.ViewManager; 8 | 9 | import java.util.Arrays; 10 | import java.util.Collections; 11 | import java.util.List; 12 | import java.util.ArrayList; 13 | 14 | public class ExtraDimensionsPackage implements ReactPackage { 15 | 16 | public List createViewManagers(ReactApplicationContext reactContext) { 17 | return Arrays.asList(); 18 | } 19 | 20 | public List> createJSModules() { 21 | return Collections.emptyList(); 22 | } 23 | 24 | @Override 25 | public List createNativeModules(ReactApplicationContext reactContext) { 26 | List modules = new ArrayList<>(); 27 | 28 | modules.add(new ExtraDimensionsModule(reactContext)); 29 | 30 | return modules; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sunhat/react-native-extra-dimensions-android/940ffe2c76d59b6c7c66da04a956c044127949ba/demo.png -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | declare type Dimensions = 2 | | "REAL_WINDOW_HEIGHT" 3 | | "REAL_WINDOW_WIDTH" 4 | | "STATUS_BAR_HEIGHT" 5 | | "SOFT_MENU_BAR_HEIGHT" 6 | | "SMART_BAR_HEIGHT"; 7 | 8 | declare interface ExtraDimensions { 9 | get: (dim: Dimensions) => number; 10 | getRealWindowHeight: () => number; 11 | getRealWindowWidth: () => number; 12 | getStatusBarHeight: () => number; 13 | getSoftMenuBarHeight: () => number; 14 | getSmartBarHeight: () => number; 15 | isSoftMenuBarEnabled: () => number; 16 | } 17 | 18 | declare module "react-native-extra-dimensions-android" { 19 | const instance: ExtraDimensions; 20 | export = instance; 21 | } 22 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import { NativeModules, Platform } from 'react-native'; 2 | 3 | export function get(dim) { 4 | if (Platform.OS !== 'android') { 5 | 6 | console.warn('react-native-extra-dimensions-android is only available on Android. Trying to access', dim); 7 | return 0; 8 | } else { // android 9 | try { 10 | if (!NativeModules.ExtraDimensions) { 11 | throw "ExtraDimensions not defined. Try rebuilding your project. e.g. react-native run-android"; 12 | } 13 | const result = NativeModules.ExtraDimensions[dim]; 14 | 15 | if (typeof result !== 'number') { 16 | return result; 17 | } 18 | return result; 19 | } catch (e) { 20 | console.error(e); 21 | } 22 | } 23 | } 24 | 25 | export function getRealWindowHeight() { 26 | return get('REAL_WINDOW_HEIGHT'); 27 | } 28 | 29 | export function getRealWindowWidth() { 30 | return get('REAL_WINDOW_WIDTH'); 31 | } 32 | 33 | export function getStatusBarHeight() { 34 | return get('STATUS_BAR_HEIGHT'); 35 | } 36 | 37 | export function getSoftMenuBarHeight() { 38 | return get('SOFT_MENU_BAR_HEIGHT'); 39 | } 40 | 41 | export function getSmartBarHeight() { 42 | return get('SMART_BAR_HEIGHT'); 43 | } 44 | 45 | export function isSoftMenuBarEnabled() { 46 | return get('SOFT_MENU_BAR_ENABLED'); 47 | } 48 | 49 | // stay compatible with pre-es6 exports 50 | export default { 51 | get, 52 | getRealWindowHeight, 53 | getRealWindowWidth, 54 | getStatusBarHeight, 55 | getSoftMenuBarHeight, 56 | getSmartBarHeight, 57 | isSoftMenuBarEnabled 58 | } 59 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-extra-dimensions-android", 3 | "version": "1.2.5", 4 | "description": "Access additional display metrics on Android devices: status bar height, soft menu bar height, real screen size.", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/Sunhat/react-native-extra-dimensions-android" 9 | }, 10 | "files": [ 11 | "android", 12 | "index", 13 | "README.md", 14 | "LICENSE" 15 | ], 16 | "keywords": [ 17 | "react-native", 18 | "react", 19 | "android" 20 | ], 21 | "author": "Jack Hsu (http://jaysoo.ca/)", 22 | "license": "ISC" 23 | } 24 | -------------------------------------------------------------------------------- /react-native.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | dependency: { 3 | platforms: { 4 | android: { 5 | packageInstance: "new ExtraDimensionsPackage()" 6 | } 7 | } 8 | } 9 | }; 10 | --------------------------------------------------------------------------------