├── .gitignore ├── README.md ├── android ├── README.md ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── utils │ └── toolkit │ ├── UtilsToolkitModule.java │ └── UtilsToolkitPackage.java ├── example ├── .buckconfig ├── .editorconfig ├── .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 │ ├── example.xcodeproj │ │ ├── project.pbxproj │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── example.xcscheme │ ├── example.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ ├── 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 └── package.json ├── index.ts ├── ios ├── UtilsToolkit.h ├── UtilsToolkit.m ├── UtilsToolkit.xcodeproj │ └── project.pbxproj └── UtilsToolkit.xcworkspace │ └── contents.xcworkspacedata ├── mock.js ├── package.json ├── react-native-utils-toolkit.podspec └── toolkit ├── devicesWithNotch.ts ├── model.ts ├── ueScale.ts ├── useAppState.ts ├── useArray.ts ├── useBackHandler.ts ├── useDetectDevice.ts ├── useDeviceOrientation.ts └── useValidation.ts /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # node.js 6 | # 7 | node_modules/ 8 | npm-debug.log 9 | yarn-error.log 10 | 11 | # Xcode 12 | # 13 | build/ 14 | *.pbxuser 15 | !default.pbxuser 16 | *.mode1v3 17 | !default.mode1v3 18 | *.mode2v3 19 | !default.mode2v3 20 | *.perspectivev3 21 | !default.perspectivev3 22 | xcuserdata 23 | *.xccheckout 24 | *.moved-aside 25 | DerivedData 26 | *.hmap 27 | *.ipa 28 | *.xcuserstate 29 | project.xcworkspace 30 | 31 | # Android/IntelliJ 32 | # 33 | build/ 34 | .idea 35 | .gradle 36 | local.properties 37 | *.iml 38 | 39 | # BUCK 40 | buck-out/ 41 | \.buckd/ 42 | *.keystore 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-native-utils-toolkit 2 | Provide solutions to make your app flexible for different screen sizes, different devices. 3 | When developing with react-native, you need to manually adjust your app to look great on a variety of different screen sizes. 4 | This package provides some simple tooling to make your scaling a whole lot easier. 5 | 6 | ## Getting started 7 | ```js 8 | yarn add react-native-utils-toolkit 9 | ``` 10 | or 11 | ```js 12 | npm i react-native-utils-toolkit 13 | ``` 14 | 15 | ### RN Version < 0.60 16 | ```js 17 | react-native link react-native-utils-toolkit 18 | ``` 19 | 20 | ### Run IOS 21 | ```js 22 | cd ios && pod install 23 | react-native run-ios 24 | ``` 25 | 26 | ### Run Android 27 | ```js 28 | react-native run-android 29 | ``` 30 | 31 | ### Jest setup 32 | ```js 33 | jest.mock('react-native-utils-toolkit', () => { 34 | const UtilsToolkit = require('react-native-utils-toolkit/mock'); 35 | return UtilsToolkit; 36 | }); 37 | ``` 38 | ### Documents 39 | | API | Type | Description | 40 | | ------------------ | -------------------- | ----------------------------------------------------------------------- | 41 | | scale | Function | Will return a linear scaled result of the provided size | 42 | | fontScale | Function | Will return a linear scaled result of the font size provided | 43 | | deviceInch | Number | Inch of device | 44 | | hasNotch | Boolean | Tells if the device has a notch | 45 | | isAndroid | Boolean | Tells if the device is Android operating system | 46 | | isIOS | Boolean | Tells if the device is IOS operating system | 47 | | isSmallDevice | Boolean | Tells the device has a screen size smaller than 4.8 inches | 48 | | isTablet | Boolean | Tells if the device is a tablet | 49 | | width | Number | Screen width | 50 | | height | Number | Screen height | 51 | |useDeviceOrientation| Hooks API | Device orientation detection | 52 | | useBackHandler | Hooks API | Detects hardware button presses for back navigation | 53 | | useAppState | Hooks API | Can tell you if the app is in the foreground or background, and notify you when the state changes | 54 | 55 | #### Source code demo 56 | [react-native-template-components](https://github.com/hoaphantn7604/react-native-template-components) A beautiful template for React Native. 57 | 58 | ### Demo 59 | 60 | ![](https://github.com/hoaphantn7604/file-upload/blob/master/document/scale/demo.png) 61 | 62 | ## Usage 63 | ```js 64 | import React from 'react'; 65 | import {SafeAreaView, ScrollView, StyleSheet, Text, View} from 'react-native'; 66 | import {useBackHandler, useAppState, useDetectDevice, useScale, useDeviceOrientation} from 'react-native-utils-toolkit'; 67 | 68 | const {scale, fontScale} = useScale; 69 | const { 70 | deviceInch, 71 | hasNotch, 72 | height, 73 | width, 74 | isAndroid, 75 | isIOS, 76 | isSmallDevice, 77 | isTablet, 78 | } = useDetectDevice; 79 | 80 | const App = () => { 81 | const deviceOrientation = useDeviceOrientation(); 82 | console.log('deviceOrientation', deviceOrientation); // PORTRAIT or LANDSCAPE 83 | 84 | useBackHandler(() => { 85 | console.log('On goback'); 86 | }, []); 87 | 88 | useAppState(state => { 89 | console.log('App State', state); 90 | }, []); 91 | 92 | return ( 93 | 94 | 95 | Device width: {width} 96 | Device height: {height} 97 | Device inch: {deviceInch} 98 | isAndroid: {isAndroid.toString()} 99 | isIOS: {isIOS.toString()} 100 | hasNotch: {hasNotch.toString()} 101 | isTablet: {isTablet.toString()} 102 | isSmallDevice: {isSmallDevice.toString()} 103 | 104 | 150x150 105 | 106 | Scale: {scale(150)}x{scale(150)} 107 | 108 | 109 | 110 | 111 | ); 112 | }; 113 | 114 | const styles = StyleSheet.create({ 115 | container: { 116 | flex: 1, 117 | alignItems: 'center', 118 | justifyContent: 'center', 119 | }, 120 | fontScale: { 121 | fontSize: fontScale(16), 122 | }, 123 | box: { 124 | width: scale(150), 125 | height: scale(150), 126 | backgroundColor: 'black', 127 | alignItems: 'center', 128 | justifyContent: 'center', 129 | margin: scale(16), 130 | }, 131 | color: { 132 | color: 'white', 133 | }, 134 | }); 135 | 136 | export default App; 137 | 138 | ``` -------------------------------------------------------------------------------- /android/README.md: -------------------------------------------------------------------------------- 1 | README 2 | ====== 3 | 4 | If you want to publish the lib as a maven dependency, follow these steps before publishing a new version to npm: 5 | 6 | 1. Be sure to have the Android [SDK](https://developer.android.com/studio/index.html) and [NDK](https://developer.android.com/ndk/guides/index.html) installed 7 | 2. Be sure to have a `local.properties` file in this folder that points to the Android SDK and NDK 8 | ``` 9 | ndk.dir=/Users/{username}/Library/Android/sdk/ndk-bundle 10 | sdk.dir=/Users/{username}/Library/Android/sdk 11 | ``` 12 | 3. Delete the `maven` folder 13 | 4. Run `./gradlew installArchives` 14 | 5. Verify that latest set of generated files is in the maven folder with the correct version number 15 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | // android/build.gradle 2 | 3 | // based on: 4 | // 5 | // * https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle 6 | // original location: 7 | // - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/build.gradle 8 | // 9 | // * https://github.com/facebook/react-native/blob/0.60-stable/template/android/app/build.gradle 10 | // original location: 11 | // - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle 12 | 13 | def DEFAULT_COMPILE_SDK_VERSION = 28 14 | def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3' 15 | def DEFAULT_MIN_SDK_VERSION = 16 16 | def DEFAULT_TARGET_SDK_VERSION = 28 17 | 18 | def safeExtGet(prop, fallback) { 19 | rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback 20 | } 21 | 22 | buildscript { 23 | // The Android Gradle plugin is only required when opening the android folder stand-alone. 24 | // This avoids unnecessary downloads and potential conflicts when the library is included as a 25 | // module dependency in an application project. 26 | // ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies 27 | if (project == rootProject) { 28 | repositories { 29 | google() 30 | mavenCentral() 31 | jcenter() 32 | } 33 | dependencies { 34 | classpath 'com.android.tools.build:gradle:3.5.3' 35 | } 36 | } 37 | } 38 | 39 | apply plugin: 'com.android.library' 40 | 41 | android { 42 | compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION) 43 | buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION) 44 | defaultConfig { 45 | minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION) 46 | targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION) 47 | versionCode 1 48 | versionName "1.0" 49 | } 50 | lintOptions { 51 | abortOnError false 52 | } 53 | } 54 | 55 | repositories { 56 | // ref: https://www.baeldung.com/maven-local-repository 57 | mavenLocal() 58 | maven { 59 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 60 | url "$rootDir/../node_modules/react-native/android" 61 | } 62 | maven { 63 | // Android JSC is installed from npm 64 | url "$rootDir/../node_modules/jsc-android/dist" 65 | } 66 | google() 67 | mavenCentral() 68 | jcenter() 69 | } 70 | 71 | dependencies { 72 | //noinspection GradleDynamicVersion 73 | implementation 'com.facebook.react:react-native:+' // From node_modules 74 | } 75 | 76 | def configureReactNativePom(def pom) { 77 | def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text) 78 | 79 | pom.project { 80 | name packageJson.title 81 | artifactId packageJson.name 82 | version = packageJson.version 83 | group = "com.utils.toolkit" 84 | description packageJson.description 85 | url packageJson.repository.baseUrl 86 | 87 | licenses { 88 | license { 89 | name packageJson.license 90 | url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename 91 | distribution 'repo' 92 | } 93 | } 94 | 95 | developers { 96 | developer { 97 | id packageJson.author.username 98 | name packageJson.author.name 99 | } 100 | } 101 | } 102 | } 103 | 104 | afterEvaluate { project -> 105 | // some Gradle build hooks ref: 106 | // https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html 107 | task androidJavadoc(type: Javadoc) { 108 | source = android.sourceSets.main.java.srcDirs 109 | // classpath += files(android.bootClasspath) 110 | // classpath += files(project.getConfigurations().getByName('compile').asList()) 111 | include '**/*.java' 112 | } 113 | 114 | task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) { 115 | classifier = 'javadoc' 116 | from androidJavadoc.destinationDir 117 | } 118 | 119 | task androidSourcesJar(type: Jar) { 120 | classifier = 'sources' 121 | from android.sourceSets.main.java.srcDirs 122 | include '**/*.java' 123 | } 124 | 125 | android.libraryVariants.all { variant -> 126 | def name = variant.name.capitalize() 127 | def javaCompileTask = variant.javaCompileProvider.get() 128 | 129 | task "jar${name}"(type: Jar, dependsOn: javaCompileTask) { 130 | from javaCompileTask.destinationDir 131 | } 132 | } 133 | 134 | artifacts { 135 | archives androidSourcesJar 136 | archives androidJavadocJar 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /android/src/main/java/com/utils/toolkit/UtilsToolkitModule.java: -------------------------------------------------------------------------------- 1 | package com.utils.toolkit; 2 | 3 | import android.content.res.Configuration; 4 | import android.os.Build; 5 | import android.util.DisplayMetrics; 6 | import android.view.WindowManager; 7 | 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | 11 | import com.facebook.react.bridge.ReactApplicationContext; 12 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 13 | import com.facebook.react.bridge.ReactMethod; 14 | import com.facebook.react.bridge.Callback; 15 | 16 | 17 | public class UtilsToolkitModule extends ReactContextBaseJavaModule { 18 | 19 | private final ReactApplicationContext reactContext; 20 | 21 | public UtilsToolkitModule(ReactApplicationContext reactContext) { 22 | super(reactContext); 23 | this.reactContext = reactContext; 24 | } 25 | 26 | @Override 27 | public String getName() { 28 | return "UtilsToolkit"; 29 | } 30 | 31 | @Override 32 | public Map getConstants() { 33 | final Map constants = new HashMap<>(); 34 | constants.put("checkTablet", isTablet()); 35 | constants.put("checkSmallDevice", isSmallDevice()); 36 | constants.put("deviceInch", deviceInch()); 37 | constants.put("getModel", getModel()); 38 | constants.put("getBrand", getBrand()); 39 | 40 | return constants; 41 | } 42 | 43 | public boolean isTablet() { 44 | // TODO: Implement some actually useful functionality 45 | if ((reactContext.getResources().getConfiguration().screenLayout & 46 | Configuration.SCREENLAYOUT_SIZE_MASK) >= 47 | Configuration.SCREENLAYOUT_SIZE_LARGE) { 48 | return true; 49 | } 50 | return false; 51 | } 52 | 53 | public boolean isSmallDevice() { 54 | // TODO: Implement some actually useful functionality 55 | double screenInches = deviceInch(); 56 | 57 | if (screenInches < 4.8) { 58 | return true; 59 | } 60 | return false; 61 | } 62 | 63 | public double deviceInch() { 64 | // TODO: Implement some actually useful functionality 65 | DisplayMetrics dm = reactContext.getResources().getDisplayMetrics(); 66 | 67 | WindowManager windowManager = (WindowManager) reactContext.getSystemService(reactContext.WINDOW_SERVICE); 68 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { 69 | windowManager.getDefaultDisplay().getRealMetrics(dm); 70 | } else { 71 | windowManager.getDefaultDisplay().getMetrics(dm); 72 | } 73 | 74 | double x = Math.pow(dm.widthPixels / dm.xdpi, 2); 75 | double y = Math.pow(dm.heightPixels / dm.xdpi, 2); 76 | double screenInches = Math.sqrt(x + y); 77 | 78 | if(screenInches < 30){ 79 | return screenInches; 80 | }else { 81 | double density = dm.density * 160; 82 | double x2 = Math.pow(dm.widthPixels / density, 2); 83 | double y2 = Math.pow(dm.heightPixels / density, 2); 84 | double screenInches2 = Math.sqrt(x2 + y2); 85 | 86 | return screenInches2; 87 | } 88 | 89 | } 90 | 91 | public String getModel() { 92 | // TODO: Implement some actually useful functionality 93 | String modelName = Build.MODEL; 94 | 95 | return modelName; 96 | } 97 | 98 | public String getBrand() { 99 | // TODO: Implement some actually useful functionality 100 | String manufacturer = Build.MANUFACTURER; 101 | 102 | return manufacturer; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /android/src/main/java/com/utils/toolkit/UtilsToolkitPackage.java: -------------------------------------------------------------------------------- 1 | package com.utils.toolkit; 2 | 3 | import java.util.Arrays; 4 | import java.util.Collections; 5 | import java.util.List; 6 | 7 | import com.facebook.react.ReactPackage; 8 | import com.facebook.react.bridge.NativeModule; 9 | import com.facebook.react.bridge.ReactApplicationContext; 10 | import com.facebook.react.uimanager.ViewManager; 11 | import com.facebook.react.bridge.JavaScriptModule; 12 | 13 | public class UtilsToolkitPackage implements ReactPackage { 14 | @Override 15 | public List createNativeModules(ReactApplicationContext reactContext) { 16 | return Arrays.asList(new UtilsToolkitModule(reactContext)); 17 | } 18 | 19 | @Override 20 | public List createViewManagers(ReactApplicationContext reactContext) { 21 | return Collections.emptyList(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /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/.editorconfig: -------------------------------------------------------------------------------- 1 | # Windows files 2 | [*.bat] 3 | end_of_line = crlf 4 | -------------------------------------------------------------------------------- /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 | ; Flow doesn't support platforms 12 | .*/Libraries/Utilities/LoadingView.js 13 | 14 | [untyped] 15 | .*/node_modules/@react-native-community/cli/.*/.* 16 | 17 | [include] 18 | 19 | [libs] 20 | node_modules/react-native/interface.js 21 | node_modules/react-native/flow/ 22 | 23 | [options] 24 | emoji=true 25 | 26 | esproposal.optional_chaining=enable 27 | esproposal.nullish_coalescing=enable 28 | 29 | exact_by_default=true 30 | 31 | module.file_ext=.js 32 | module.file_ext=.json 33 | module.file_ext=.ios.js 34 | 35 | munge_underscores=true 36 | 37 | module.name_mapper='^react-native/\(.*\)$' -> '/node_modules/react-native/\1' 38 | 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' 39 | 40 | suppress_type=$FlowIssue 41 | suppress_type=$FlowFixMe 42 | suppress_type=$FlowFixMeProps 43 | suppress_type=$FlowFixMeState 44 | 45 | [lints] 46 | sketchy-null-number=warn 47 | sketchy-null-mixed=warn 48 | sketchy-number=warn 49 | untyped-type-import=warn 50 | nonstrict-import=warn 51 | deprecated-type=warn 52 | unsafe-getters-setters=warn 53 | unnecessary-invariant=warn 54 | signature-verification-failure=warn 55 | 56 | [strict] 57 | deprecated-type 58 | nonstrict-import 59 | sketchy-null 60 | unclear-type 61 | unsafe-getters-setters 62 | untyped-import 63 | untyped-type-import 64 | 65 | [version] 66 | ^0.137.0 67 | -------------------------------------------------------------------------------- /example/.gitattributes: -------------------------------------------------------------------------------- 1 | # Windows files should use crlf line endings 2 | # https://help.github.com/articles/dealing-with-line-endings/ 3 | *.bat text eol=crlf 4 | -------------------------------------------------------------------------------- /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 | # Android/IntelliJ 25 | # 26 | build/ 27 | .idea 28 | .gradle 29 | local.properties 30 | *.iml 31 | 32 | # node.js 33 | # 34 | node_modules/ 35 | npm-debug.log 36 | yarn-error.log 37 | 38 | # BUCK 39 | buck-out/ 40 | \.buckd/ 41 | *.keystore 42 | !debug.keystore 43 | 44 | # fastlane 45 | # 46 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 47 | # screenshots whenever they are needed. 48 | # For more information about the recommended setup visit: 49 | # https://docs.fastlane.tools/best-practices/source-control/ 50 | 51 | */fastlane/report.xml 52 | */fastlane/Preview.html 53 | */fastlane/screenshots 54 | 55 | # Bundle artifact 56 | *.jsbundle 57 | 58 | # CocoaPods 59 | /ios/Pods/ 60 | -------------------------------------------------------------------------------- /example/.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | bracketSpacing: false, 3 | jsxBracketSameLine: true, 4 | singleQuote: true, 5 | trailingComma: 'all', 6 | arrowParens: 'avoid', 7 | }; 8 | -------------------------------------------------------------------------------- /example/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /example/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import {SafeAreaView, ScrollView, StyleSheet, Text, View} from 'react-native'; 3 | import { 4 | useBackHandler, 5 | useAppState, 6 | useDetectDevice, 7 | useDeviceOrientation, 8 | useScale, 9 | } from 'react-native-utils-toolkit'; 10 | const {scale, fontScale} = useScale; 11 | const { 12 | deviceInch, 13 | hasNotch, 14 | height, 15 | width, 16 | isAndroid, 17 | isIOS, 18 | isSmallDevice, 19 | isTablet, 20 | } = useDetectDevice; 21 | 22 | const App = () => { 23 | const deviceOrientation = useDeviceOrientation(); 24 | console.log('deviceOrientation', deviceOrientation); // PORTRAIT or LANDSCAPE 25 | 26 | useBackHandler(() => { 27 | console.log('On goback'); 28 | }, []); 29 | 30 | useAppState(state => { 31 | console.log('App State', state); 32 | }, []); 33 | 34 | return ( 35 | 36 | 37 | Device width: {width} 38 | Device height: {height} 39 | Device inch: {deviceInch} 40 | isAndroid: {isAndroid.toString()} 41 | isIOS: {isIOS.toString()} 42 | hasNotch: {hasNotch.toString()} 43 | isTablet: {isTablet.toString()} 44 | 45 | isSmallDevice: {isSmallDevice.toString()} 46 | 47 | 48 | 150x150 49 | 50 | Scale: {scale(150)}x{scale(150)} 51 | 52 | 53 | 54 | 55 | ); 56 | }; 57 | 58 | const styles = StyleSheet.create({ 59 | container: { 60 | flex: 1, 61 | alignItems: 'center', 62 | justifyContent: 'center', 63 | }, 64 | fontScale: { 65 | fontSize: fontScale(16), 66 | }, 67 | box: { 68 | width: scale(150), 69 | height: scale(150), 70 | backgroundColor: 'black', 71 | alignItems: 'center', 72 | justifyContent: 'center', 73 | margin: 16, 74 | }, 75 | color: { 76 | color: 'white', 77 | }, 78 | }); 79 | 80 | export default App; 81 | -------------------------------------------------------------------------------- /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 | ndkVersion rootProject.ext.ndkVersion 125 | 126 | compileSdkVersion rootProject.ext.compileSdkVersion 127 | 128 | compileOptions { 129 | sourceCompatibility JavaVersion.VERSION_1_8 130 | targetCompatibility JavaVersion.VERSION_1_8 131 | } 132 | 133 | defaultConfig { 134 | applicationId "com.example" 135 | minSdkVersion rootProject.ext.minSdkVersion 136 | targetSdkVersion rootProject.ext.targetSdkVersion 137 | versionCode 1 138 | versionName "1.0" 139 | } 140 | splits { 141 | abi { 142 | reset() 143 | enable enableSeparateBuildPerCPUArchitecture 144 | universalApk false // If true, also generate a universal APK 145 | include "armeabi-v7a", "x86", "arm64-v8a", "x86_64" 146 | } 147 | } 148 | signingConfigs { 149 | debug { 150 | storeFile file('debug.keystore') 151 | storePassword 'android' 152 | keyAlias 'androiddebugkey' 153 | keyPassword 'android' 154 | } 155 | } 156 | buildTypes { 157 | debug { 158 | signingConfig signingConfigs.debug 159 | } 160 | release { 161 | // Caution! In production, you need to generate your own keystore file. 162 | // see https://reactnative.dev/docs/signed-apk-android. 163 | signingConfig signingConfigs.debug 164 | minifyEnabled enableProguardInReleaseBuilds 165 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 166 | } 167 | } 168 | 169 | // applicationVariants are e.g. debug, release 170 | applicationVariants.all { variant -> 171 | variant.outputs.each { output -> 172 | // For each separate APK per architecture, set a unique version code as described here: 173 | // https://developer.android.com/studio/build/configure-apk-splits.html 174 | // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc. 175 | def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4] 176 | def abi = output.getFilter(OutputFile.ABI) 177 | if (abi != null) { // null for the universal-debug, universal-release variants 178 | output.versionCodeOverride = 179 | defaultConfig.versionCode * 1000 + versionCodes.get(abi) 180 | } 181 | 182 | } 183 | } 184 | } 185 | 186 | dependencies { 187 | implementation fileTree(dir: "libs", include: ["*.jar"]) 188 | //noinspection GradleDynamicVersion 189 | implementation "com.facebook.react:react-native:+" // From node_modules 190 | 191 | implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" 192 | 193 | debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") { 194 | exclude group:'com.facebook.fbjni' 195 | } 196 | 197 | debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { 198 | exclude group:'com.facebook.flipper' 199 | exclude group:'com.squareup.okhttp3', module:'okhttp' 200 | } 201 | 202 | debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") { 203 | exclude group:'com.facebook.flipper' 204 | } 205 | 206 | if (enableHermes) { 207 | def hermesPath = "../../node_modules/hermes-engine/android/"; 208 | debugImplementation files(hermesPath + "hermes-debug.aar") 209 | releaseImplementation files(hermesPath + "hermes-release.aar") 210 | } else { 211 | implementation jscFlavor 212 | } 213 | } 214 | 215 | // Run this once to be able to run the application with BUCK 216 | // puts all compile dependencies into folder libs for BUCK to use 217 | task copyDownloadableDepsToLibs(type: Copy) { 218 | from configurations.compile 219 | into 'libs' 220 | } 221 | 222 | task prepareKotlinBuildScriptModel { 223 | 224 | } 225 | 226 | task wrapper(type: Wrapper){ 227 | gradleVersion = '4.1.0' 228 | } 229 | 230 | apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) 231 | -------------------------------------------------------------------------------- /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/hoaphantn7604/react-native-utils-toolkit/8859614e1869a6393a2832a22dede5294fd7a124/example/android/app/debug.keystore -------------------------------------------------------------------------------- /example/android/app/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoaphantn7604/react-native-utils-toolkit/8859614e1869a6393a2832a22dede5294fd7a124/example/android/app/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/android/app/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1.0-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /example/android/app/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 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /example/android/app/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 execute 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 execute 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 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /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 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /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 | 7 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/example/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import com.facebook.react.ReactActivity; 4 | 5 | public class MainActivity extends ReactActivity { 6 | 7 | /** 8 | * Returns the name of the main component registered from JavaScript. This is used to schedule 9 | * rendering of the component. 10 | */ 11 | @Override 12 | protected String getMainComponentName() { 13 | return "example"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /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 | public class MainApplication extends Application implements ReactApplication { 15 | 16 | private final ReactNativeHost mReactNativeHost = 17 | new ReactNativeHost(this) { 18 | @Override 19 | public boolean getUseDeveloperSupport() { 20 | return BuildConfig.DEBUG; 21 | } 22 | 23 | @Override 24 | protected List getPackages() { 25 | @SuppressWarnings("UnnecessaryLocalVariable") 26 | List packages = new PackageList(this).getPackages(); 27 | // Packages that cannot be autolinked yet can be added manually here, for example: 28 | // packages.add(new MyReactNativePackage()); 29 | return packages; 30 | } 31 | 32 | @Override 33 | protected String getJSMainModuleName() { 34 | return "index"; 35 | } 36 | }; 37 | 38 | @Override 39 | public ReactNativeHost getReactNativeHost() { 40 | return mReactNativeHost; 41 | } 42 | 43 | @Override 44 | public void onCreate() { 45 | super.onCreate(); 46 | SoLoader.init(this, /* native exopackage */ false); 47 | initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); 48 | } 49 | 50 | /** 51 | * Loads Flipper in React Native templates. Call this in the onCreate method with something like 52 | * initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); 53 | * 54 | * @param context 55 | * @param reactInstanceManager 56 | */ 57 | private static void initializeFlipper( 58 | Context context, ReactInstanceManager reactInstanceManager) { 59 | if (BuildConfig.DEBUG) { 60 | try { 61 | /* 62 | We use reflection here to pick up the class that initializes Flipper, 63 | since Flipper library is not available in release mode 64 | */ 65 | Class aClass = Class.forName("com.example.ReactNativeFlipper"); 66 | aClass 67 | .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class) 68 | .invoke(null, context, reactInstanceManager); 69 | } catch (ClassNotFoundException e) { 70 | e.printStackTrace(); 71 | } catch (NoSuchMethodException e) { 72 | e.printStackTrace(); 73 | } catch (IllegalAccessException e) { 74 | e.printStackTrace(); 75 | } catch (InvocationTargetException e) { 76 | e.printStackTrace(); 77 | } 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoaphantn7604/react-native-utils-toolkit/8859614e1869a6393a2832a22dede5294fd7a124/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/hoaphantn7604/react-native-utils-toolkit/8859614e1869a6393a2832a22dede5294fd7a124/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/hoaphantn7604/react-native-utils-toolkit/8859614e1869a6393a2832a22dede5294fd7a124/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/hoaphantn7604/react-native-utils-toolkit/8859614e1869a6393a2832a22dede5294fd7a124/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/hoaphantn7604/react-native-utils-toolkit/8859614e1869a6393a2832a22dede5294fd7a124/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/hoaphantn7604/react-native-utils-toolkit/8859614e1869a6393a2832a22dede5294fd7a124/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/hoaphantn7604/react-native-utils-toolkit/8859614e1869a6393a2832a22dede5294fd7a124/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/hoaphantn7604/react-native-utils-toolkit/8859614e1869a6393a2832a22dede5294fd7a124/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/hoaphantn7604/react-native-utils-toolkit/8859614e1869a6393a2832a22dede5294fd7a124/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/hoaphantn7604/react-native-utils-toolkit/8859614e1869a6393a2832a22dede5294fd7a124/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Toolkit 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.3" 6 | minSdkVersion = 21 7 | compileSdkVersion = 29 8 | targetSdkVersion = 29 9 | ndkVersion = "20.1.5948944" 10 | } 11 | repositories { 12 | google() 13 | jcenter() 14 | } 15 | dependencies { 16 | classpath("com.android.tools.build:gradle:4.1.0") 17 | // NOTE: Do not place your application dependencies here; they belong 18 | // in the individual module build.gradle files 19 | } 20 | } 21 | 22 | allprojects { 23 | repositories { 24 | mavenLocal() 25 | maven { 26 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 27 | url("$rootDir/../node_modules/react-native/android") 28 | } 29 | maven { 30 | // Android JSC is installed from npm 31 | url("$rootDir/../node_modules/jsc-android/dist") 32 | } 33 | 34 | google() 35 | jcenter() 36 | maven { url 'https://www.jitpack.io' } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /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.75.1 29 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoaphantn7604/react-native-utils-toolkit/8859614e1869a6393a2832a22dede5294fd7a124/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.7-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists -------------------------------------------------------------------------------- /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 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /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 execute 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 execute 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 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /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!( 10 | :path => config[:reactNativePath], 11 | # to enable hermes on iOS, change `false` to `true` and then install pods 12 | :hermes_enabled => false 13 | ) 14 | 15 | target 'exampleTests' do 16 | inherit! :complete 17 | # Pods for testing 18 | end 19 | 20 | # Enables Flipper. 21 | # 22 | # Note that if you have use_frameworks! enabled, Flipper will not work and 23 | # you should disable the next line. 24 | 25 | post_install do |installer| 26 | react_native_post_install(installer) 27 | end 28 | end -------------------------------------------------------------------------------- /example/ios/example.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 54; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 00E356F31AD99517003FC87E /* exampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* exampleTests.m */; }; 11 | 13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; }; 12 | 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; 13 | 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; 14 | 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; }; 15 | ACFABD8E4EAC1F86C0A6909F /* libPods-example.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D1061D21F54DB7F51BA1AD9A /* libPods-example.a */; }; 16 | F6CF1ECCF3157A4DACDE90BE /* libPods-example-exampleTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B86E4C75B0FA8A9995CAF603 /* libPods-example-exampleTests.a */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXContainerItemProxy section */ 20 | 00E356F41AD99517003FC87E /* PBXContainerItemProxy */ = { 21 | isa = PBXContainerItemProxy; 22 | containerPortal = 83CBB9F71A601CBA00E9B192 /* Project object */; 23 | proxyType = 1; 24 | remoteGlobalIDString = 13B07F861A680F5B00A75B9A; 25 | remoteInfo = example; 26 | }; 27 | /* End PBXContainerItemProxy section */ 28 | 29 | /* Begin PBXFileReference section */ 30 | 00E356EE1AD99517003FC87E /* exampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = exampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 31 | 00E356F11AD99517003FC87E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 32 | 00E356F21AD99517003FC87E /* exampleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = exampleTests.m; sourceTree = ""; }; 33 | 13B07F961A680F5B00A75B9A /* example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 34 | 13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = example/AppDelegate.h; sourceTree = ""; }; 35 | 13B07FB01A68108700A75B9A /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppDelegate.m; path = example/AppDelegate.m; sourceTree = ""; }; 36 | 13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = example/Images.xcassets; sourceTree = ""; }; 37 | 13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = example/Info.plist; sourceTree = ""; }; 38 | 13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = example/main.m; sourceTree = ""; }; 39 | 65A85A2426D9BF343FC670FD /* Pods-example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example.debug.xcconfig"; path = "Target Support Files/Pods-example/Pods-example.debug.xcconfig"; sourceTree = ""; }; 40 | 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = example/LaunchScreen.storyboard; sourceTree = ""; }; 41 | B86E4C75B0FA8A9995CAF603 /* libPods-example-exampleTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-example-exampleTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 42 | BBD444D6909BB926BD2CE7F7 /* Pods-example-exampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example-exampleTests.debug.xcconfig"; path = "Target Support Files/Pods-example-exampleTests/Pods-example-exampleTests.debug.xcconfig"; sourceTree = ""; }; 43 | D1061D21F54DB7F51BA1AD9A /* libPods-example.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-example.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 44 | EB4B51677B1B03A9FDC93366 /* Pods-example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example.release.xcconfig"; path = "Target Support Files/Pods-example/Pods-example.release.xcconfig"; sourceTree = ""; }; 45 | ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; 46 | FB547C5AB84C21D1FEF1A365 /* Pods-example-exampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example-exampleTests.release.xcconfig"; path = "Target Support Files/Pods-example-exampleTests/Pods-example-exampleTests.release.xcconfig"; sourceTree = ""; }; 47 | /* End PBXFileReference section */ 48 | 49 | /* Begin PBXFrameworksBuildPhase section */ 50 | 00E356EB1AD99517003FC87E /* Frameworks */ = { 51 | isa = PBXFrameworksBuildPhase; 52 | buildActionMask = 2147483647; 53 | files = ( 54 | F6CF1ECCF3157A4DACDE90BE /* libPods-example-exampleTests.a in Frameworks */, 55 | ); 56 | runOnlyForDeploymentPostprocessing = 0; 57 | }; 58 | 13B07F8C1A680F5B00A75B9A /* Frameworks */ = { 59 | isa = PBXFrameworksBuildPhase; 60 | buildActionMask = 2147483647; 61 | files = ( 62 | ACFABD8E4EAC1F86C0A6909F /* libPods-example.a in Frameworks */, 63 | ); 64 | runOnlyForDeploymentPostprocessing = 0; 65 | }; 66 | /* End PBXFrameworksBuildPhase section */ 67 | 68 | /* Begin PBXGroup section */ 69 | 00E356EF1AD99517003FC87E /* exampleTests */ = { 70 | isa = PBXGroup; 71 | children = ( 72 | 00E356F21AD99517003FC87E /* exampleTests.m */, 73 | 00E356F01AD99517003FC87E /* Supporting Files */, 74 | ); 75 | path = exampleTests; 76 | sourceTree = ""; 77 | }; 78 | 00E356F01AD99517003FC87E /* Supporting Files */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | 00E356F11AD99517003FC87E /* Info.plist */, 82 | ); 83 | name = "Supporting Files"; 84 | sourceTree = ""; 85 | }; 86 | 0B2AC7ECC8FC5CBD32B1BE1E /* Pods */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | 65A85A2426D9BF343FC670FD /* Pods-example.debug.xcconfig */, 90 | EB4B51677B1B03A9FDC93366 /* Pods-example.release.xcconfig */, 91 | BBD444D6909BB926BD2CE7F7 /* Pods-example-exampleTests.debug.xcconfig */, 92 | FB547C5AB84C21D1FEF1A365 /* Pods-example-exampleTests.release.xcconfig */, 93 | ); 94 | path = Pods; 95 | sourceTree = ""; 96 | }; 97 | 13B07FAE1A68108700A75B9A /* example */ = { 98 | isa = PBXGroup; 99 | children = ( 100 | 13B07FAF1A68108700A75B9A /* AppDelegate.h */, 101 | 13B07FB01A68108700A75B9A /* AppDelegate.m */, 102 | 13B07FB51A68108700A75B9A /* Images.xcassets */, 103 | 13B07FB61A68108700A75B9A /* Info.plist */, 104 | 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */, 105 | 13B07FB71A68108700A75B9A /* main.m */, 106 | ); 107 | name = example; 108 | sourceTree = ""; 109 | }; 110 | 2D16E6871FA4F8E400B85C8A /* Frameworks */ = { 111 | isa = PBXGroup; 112 | children = ( 113 | ED297162215061F000B7C4FE /* JavaScriptCore.framework */, 114 | D1061D21F54DB7F51BA1AD9A /* libPods-example.a */, 115 | B86E4C75B0FA8A9995CAF603 /* libPods-example-exampleTests.a */, 116 | ); 117 | name = Frameworks; 118 | sourceTree = ""; 119 | }; 120 | 832341AE1AAA6A7D00B99B32 /* Libraries */ = { 121 | isa = PBXGroup; 122 | children = ( 123 | ); 124 | name = Libraries; 125 | sourceTree = ""; 126 | }; 127 | 83CBB9F61A601CBA00E9B192 = { 128 | isa = PBXGroup; 129 | children = ( 130 | 13B07FAE1A68108700A75B9A /* example */, 131 | 832341AE1AAA6A7D00B99B32 /* Libraries */, 132 | 00E356EF1AD99517003FC87E /* exampleTests */, 133 | 83CBBA001A601CBA00E9B192 /* Products */, 134 | 2D16E6871FA4F8E400B85C8A /* Frameworks */, 135 | 0B2AC7ECC8FC5CBD32B1BE1E /* Pods */, 136 | ); 137 | indentWidth = 2; 138 | sourceTree = ""; 139 | tabWidth = 2; 140 | usesTabs = 0; 141 | }; 142 | 83CBBA001A601CBA00E9B192 /* Products */ = { 143 | isa = PBXGroup; 144 | children = ( 145 | 13B07F961A680F5B00A75B9A /* example.app */, 146 | 00E356EE1AD99517003FC87E /* exampleTests.xctest */, 147 | ); 148 | name = Products; 149 | sourceTree = ""; 150 | }; 151 | /* End PBXGroup section */ 152 | 153 | /* Begin PBXNativeTarget section */ 154 | 00E356ED1AD99517003FC87E /* exampleTests */ = { 155 | isa = PBXNativeTarget; 156 | buildConfigurationList = 00E357021AD99517003FC87E /* Build configuration list for PBXNativeTarget "exampleTests" */; 157 | buildPhases = ( 158 | B52DB23811853FD97F2A85B3 /* [CP] Check Pods Manifest.lock */, 159 | 00E356EA1AD99517003FC87E /* Sources */, 160 | 00E356EB1AD99517003FC87E /* Frameworks */, 161 | 00E356EC1AD99517003FC87E /* Resources */, 162 | 34E5038093BACCFA4F81FCA8 /* [CP] Copy Pods Resources */, 163 | ); 164 | buildRules = ( 165 | ); 166 | dependencies = ( 167 | 00E356F51AD99517003FC87E /* PBXTargetDependency */, 168 | ); 169 | name = exampleTests; 170 | productName = exampleTests; 171 | productReference = 00E356EE1AD99517003FC87E /* exampleTests.xctest */; 172 | productType = "com.apple.product-type.bundle.unit-test"; 173 | }; 174 | 13B07F861A680F5B00A75B9A /* example */ = { 175 | isa = PBXNativeTarget; 176 | buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "example" */; 177 | buildPhases = ( 178 | E2520552B7ABC59873B1B7C9 /* [CP] Check Pods Manifest.lock */, 179 | FD10A7F022414F080027D42C /* Start Packager */, 180 | 13B07F871A680F5B00A75B9A /* Sources */, 181 | 13B07F8C1A680F5B00A75B9A /* Frameworks */, 182 | 13B07F8E1A680F5B00A75B9A /* Resources */, 183 | 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */, 184 | 7EA0C0043AE35A581C7A0D12 /* [CP] Copy Pods Resources */, 185 | ); 186 | buildRules = ( 187 | ); 188 | dependencies = ( 189 | ); 190 | name = example; 191 | productName = example; 192 | productReference = 13B07F961A680F5B00A75B9A /* example.app */; 193 | productType = "com.apple.product-type.application"; 194 | }; 195 | /* End PBXNativeTarget section */ 196 | 197 | /* Begin PBXProject section */ 198 | 83CBB9F71A601CBA00E9B192 /* Project object */ = { 199 | isa = PBXProject; 200 | attributes = { 201 | LastUpgradeCheck = 1210; 202 | TargetAttributes = { 203 | 00E356ED1AD99517003FC87E = { 204 | CreatedOnToolsVersion = 6.2; 205 | TestTargetID = 13B07F861A680F5B00A75B9A; 206 | }; 207 | 13B07F861A680F5B00A75B9A = { 208 | LastSwiftMigration = 1120; 209 | }; 210 | }; 211 | }; 212 | buildConfigurationList = 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "example" */; 213 | compatibilityVersion = "Xcode 12.0"; 214 | developmentRegion = en; 215 | hasScannedForEncodings = 0; 216 | knownRegions = ( 217 | en, 218 | Base, 219 | ); 220 | mainGroup = 83CBB9F61A601CBA00E9B192; 221 | productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */; 222 | projectDirPath = ""; 223 | projectRoot = ""; 224 | targets = ( 225 | 13B07F861A680F5B00A75B9A /* example */, 226 | 00E356ED1AD99517003FC87E /* exampleTests */, 227 | ); 228 | }; 229 | /* End PBXProject section */ 230 | 231 | /* Begin PBXResourcesBuildPhase section */ 232 | 00E356EC1AD99517003FC87E /* Resources */ = { 233 | isa = PBXResourcesBuildPhase; 234 | buildActionMask = 2147483647; 235 | files = ( 236 | ); 237 | runOnlyForDeploymentPostprocessing = 0; 238 | }; 239 | 13B07F8E1A680F5B00A75B9A /* Resources */ = { 240 | isa = PBXResourcesBuildPhase; 241 | buildActionMask = 2147483647; 242 | files = ( 243 | 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */, 244 | 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */, 245 | ); 246 | runOnlyForDeploymentPostprocessing = 0; 247 | }; 248 | /* End PBXResourcesBuildPhase section */ 249 | 250 | /* Begin PBXShellScriptBuildPhase section */ 251 | 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */ = { 252 | isa = PBXShellScriptBuildPhase; 253 | buildActionMask = 2147483647; 254 | files = ( 255 | ); 256 | inputPaths = ( 257 | ); 258 | name = "Bundle React Native code and images"; 259 | outputPaths = ( 260 | ); 261 | runOnlyForDeploymentPostprocessing = 0; 262 | shellPath = /bin/sh; 263 | shellScript = "set -e\n\nexport NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh\n"; 264 | }; 265 | 34E5038093BACCFA4F81FCA8 /* [CP] Copy Pods Resources */ = { 266 | isa = PBXShellScriptBuildPhase; 267 | buildActionMask = 2147483647; 268 | files = ( 269 | ); 270 | inputFileListPaths = ( 271 | "${PODS_ROOT}/Target Support Files/Pods-example-exampleTests/Pods-example-exampleTests-resources-${CONFIGURATION}-input-files.xcfilelist", 272 | ); 273 | name = "[CP] Copy Pods Resources"; 274 | outputFileListPaths = ( 275 | "${PODS_ROOT}/Target Support Files/Pods-example-exampleTests/Pods-example-exampleTests-resources-${CONFIGURATION}-output-files.xcfilelist", 276 | ); 277 | runOnlyForDeploymentPostprocessing = 0; 278 | shellPath = /bin/sh; 279 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-example-exampleTests/Pods-example-exampleTests-resources.sh\"\n"; 280 | showEnvVarsInLog = 0; 281 | }; 282 | 7EA0C0043AE35A581C7A0D12 /* [CP] Copy Pods Resources */ = { 283 | isa = PBXShellScriptBuildPhase; 284 | buildActionMask = 2147483647; 285 | files = ( 286 | ); 287 | inputFileListPaths = ( 288 | "${PODS_ROOT}/Target Support Files/Pods-example/Pods-example-resources-${CONFIGURATION}-input-files.xcfilelist", 289 | ); 290 | name = "[CP] Copy Pods Resources"; 291 | outputFileListPaths = ( 292 | "${PODS_ROOT}/Target Support Files/Pods-example/Pods-example-resources-${CONFIGURATION}-output-files.xcfilelist", 293 | ); 294 | runOnlyForDeploymentPostprocessing = 0; 295 | shellPath = /bin/sh; 296 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-example/Pods-example-resources.sh\"\n"; 297 | showEnvVarsInLog = 0; 298 | }; 299 | B52DB23811853FD97F2A85B3 /* [CP] Check Pods Manifest.lock */ = { 300 | isa = PBXShellScriptBuildPhase; 301 | buildActionMask = 2147483647; 302 | files = ( 303 | ); 304 | inputFileListPaths = ( 305 | ); 306 | inputPaths = ( 307 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 308 | "${PODS_ROOT}/Manifest.lock", 309 | ); 310 | name = "[CP] Check Pods Manifest.lock"; 311 | outputFileListPaths = ( 312 | ); 313 | outputPaths = ( 314 | "$(DERIVED_FILE_DIR)/Pods-example-exampleTests-checkManifestLockResult.txt", 315 | ); 316 | runOnlyForDeploymentPostprocessing = 0; 317 | shellPath = /bin/sh; 318 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 319 | showEnvVarsInLog = 0; 320 | }; 321 | E2520552B7ABC59873B1B7C9 /* [CP] Check Pods Manifest.lock */ = { 322 | isa = PBXShellScriptBuildPhase; 323 | buildActionMask = 2147483647; 324 | files = ( 325 | ); 326 | inputFileListPaths = ( 327 | ); 328 | inputPaths = ( 329 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 330 | "${PODS_ROOT}/Manifest.lock", 331 | ); 332 | name = "[CP] Check Pods Manifest.lock"; 333 | outputFileListPaths = ( 334 | ); 335 | outputPaths = ( 336 | "$(DERIVED_FILE_DIR)/Pods-example-checkManifestLockResult.txt", 337 | ); 338 | runOnlyForDeploymentPostprocessing = 0; 339 | shellPath = /bin/sh; 340 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 341 | showEnvVarsInLog = 0; 342 | }; 343 | FD10A7F022414F080027D42C /* Start Packager */ = { 344 | isa = PBXShellScriptBuildPhase; 345 | buildActionMask = 2147483647; 346 | files = ( 347 | ); 348 | inputFileListPaths = ( 349 | ); 350 | inputPaths = ( 351 | ); 352 | name = "Start Packager"; 353 | outputFileListPaths = ( 354 | ); 355 | outputPaths = ( 356 | ); 357 | runOnlyForDeploymentPostprocessing = 0; 358 | shellPath = /bin/sh; 359 | shellScript = "export RCT_METRO_PORT=\"${RCT_METRO_PORT:=8081}\"\necho \"export RCT_METRO_PORT=${RCT_METRO_PORT}\" > \"${SRCROOT}/../node_modules/react-native/scripts/.packager.env\"\nif [ -z \"${RCT_NO_LAUNCH_PACKAGER+xxx}\" ] ; then\n if nc -w 5 -z localhost ${RCT_METRO_PORT} ; then\n if ! curl -s \"http://localhost:${RCT_METRO_PORT}/status\" | grep -q \"packager-status:running\" ; then\n echo \"Port ${RCT_METRO_PORT} already in use, packager is either not running or not running correctly\"\n exit 2\n fi\n else\n open \"$SRCROOT/../node_modules/react-native/scripts/launchPackager.command\" || echo \"Can't start packager automatically\"\n fi\nfi\n"; 360 | showEnvVarsInLog = 0; 361 | }; 362 | /* End PBXShellScriptBuildPhase section */ 363 | 364 | /* Begin PBXSourcesBuildPhase section */ 365 | 00E356EA1AD99517003FC87E /* Sources */ = { 366 | isa = PBXSourcesBuildPhase; 367 | buildActionMask = 2147483647; 368 | files = ( 369 | 00E356F31AD99517003FC87E /* exampleTests.m in Sources */, 370 | ); 371 | runOnlyForDeploymentPostprocessing = 0; 372 | }; 373 | 13B07F871A680F5B00A75B9A /* Sources */ = { 374 | isa = PBXSourcesBuildPhase; 375 | buildActionMask = 2147483647; 376 | files = ( 377 | 13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */, 378 | 13B07FC11A68108700A75B9A /* main.m in Sources */, 379 | ); 380 | runOnlyForDeploymentPostprocessing = 0; 381 | }; 382 | /* End PBXSourcesBuildPhase section */ 383 | 384 | /* Begin PBXTargetDependency section */ 385 | 00E356F51AD99517003FC87E /* PBXTargetDependency */ = { 386 | isa = PBXTargetDependency; 387 | target = 13B07F861A680F5B00A75B9A /* example */; 388 | targetProxy = 00E356F41AD99517003FC87E /* PBXContainerItemProxy */; 389 | }; 390 | /* End PBXTargetDependency section */ 391 | 392 | /* Begin XCBuildConfiguration section */ 393 | 00E356F61AD99517003FC87E /* Debug */ = { 394 | isa = XCBuildConfiguration; 395 | baseConfigurationReference = BBD444D6909BB926BD2CE7F7 /* Pods-example-exampleTests.debug.xcconfig */; 396 | buildSettings = { 397 | BUNDLE_LOADER = "$(TEST_HOST)"; 398 | GCC_PREPROCESSOR_DEFINITIONS = ( 399 | "DEBUG=1", 400 | "$(inherited)", 401 | ); 402 | INFOPLIST_FILE = exampleTests/Info.plist; 403 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 404 | LD_RUNPATH_SEARCH_PATHS = ( 405 | "$(inherited)", 406 | "@executable_path/Frameworks", 407 | "@loader_path/Frameworks", 408 | ); 409 | OTHER_LDFLAGS = ( 410 | "-ObjC", 411 | "-lc++", 412 | "$(inherited)", 413 | ); 414 | PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; 415 | PRODUCT_NAME = "$(TARGET_NAME)"; 416 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/example.app/example"; 417 | }; 418 | name = Debug; 419 | }; 420 | 00E356F71AD99517003FC87E /* Release */ = { 421 | isa = XCBuildConfiguration; 422 | baseConfigurationReference = FB547C5AB84C21D1FEF1A365 /* Pods-example-exampleTests.release.xcconfig */; 423 | buildSettings = { 424 | BUNDLE_LOADER = "$(TEST_HOST)"; 425 | COPY_PHASE_STRIP = NO; 426 | INFOPLIST_FILE = exampleTests/Info.plist; 427 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 428 | LD_RUNPATH_SEARCH_PATHS = ( 429 | "$(inherited)", 430 | "@executable_path/Frameworks", 431 | "@loader_path/Frameworks", 432 | ); 433 | OTHER_LDFLAGS = ( 434 | "-ObjC", 435 | "-lc++", 436 | "$(inherited)", 437 | ); 438 | PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; 439 | PRODUCT_NAME = "$(TARGET_NAME)"; 440 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/example.app/example"; 441 | }; 442 | name = Release; 443 | }; 444 | 13B07F941A680F5B00A75B9A /* Debug */ = { 445 | isa = XCBuildConfiguration; 446 | baseConfigurationReference = 65A85A2426D9BF343FC670FD /* Pods-example.debug.xcconfig */; 447 | buildSettings = { 448 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 449 | CLANG_ENABLE_MODULES = YES; 450 | CURRENT_PROJECT_VERSION = 1; 451 | ENABLE_BITCODE = NO; 452 | INFOPLIST_FILE = example/Info.plist; 453 | LD_RUNPATH_SEARCH_PATHS = ( 454 | "$(inherited)", 455 | "@executable_path/Frameworks", 456 | ); 457 | OTHER_LDFLAGS = ( 458 | "$(inherited)", 459 | "-ObjC", 460 | "-lc++", 461 | ); 462 | PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; 463 | PRODUCT_NAME = example; 464 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 465 | SWIFT_VERSION = 5.0; 466 | TARGETED_DEVICE_FAMILY = "1,2"; 467 | VERSIONING_SYSTEM = "apple-generic"; 468 | }; 469 | name = Debug; 470 | }; 471 | 13B07F951A680F5B00A75B9A /* Release */ = { 472 | isa = XCBuildConfiguration; 473 | baseConfigurationReference = EB4B51677B1B03A9FDC93366 /* Pods-example.release.xcconfig */; 474 | buildSettings = { 475 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 476 | CLANG_ENABLE_MODULES = YES; 477 | CURRENT_PROJECT_VERSION = 1; 478 | INFOPLIST_FILE = example/Info.plist; 479 | LD_RUNPATH_SEARCH_PATHS = ( 480 | "$(inherited)", 481 | "@executable_path/Frameworks", 482 | ); 483 | OTHER_LDFLAGS = ( 484 | "$(inherited)", 485 | "-ObjC", 486 | "-lc++", 487 | ); 488 | PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; 489 | PRODUCT_NAME = example; 490 | SWIFT_VERSION = 5.0; 491 | TARGETED_DEVICE_FAMILY = "1,2"; 492 | VERSIONING_SYSTEM = "apple-generic"; 493 | }; 494 | name = Release; 495 | }; 496 | 83CBBA201A601CBA00E9B192 /* Debug */ = { 497 | isa = XCBuildConfiguration; 498 | buildSettings = { 499 | ALWAYS_SEARCH_USER_PATHS = NO; 500 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 501 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 502 | CLANG_CXX_LIBRARY = "libc++"; 503 | CLANG_ENABLE_MODULES = YES; 504 | CLANG_ENABLE_OBJC_ARC = YES; 505 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 506 | CLANG_WARN_BOOL_CONVERSION = YES; 507 | CLANG_WARN_COMMA = YES; 508 | CLANG_WARN_CONSTANT_CONVERSION = YES; 509 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 510 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 511 | CLANG_WARN_EMPTY_BODY = YES; 512 | CLANG_WARN_ENUM_CONVERSION = YES; 513 | CLANG_WARN_INFINITE_RECURSION = YES; 514 | CLANG_WARN_INT_CONVERSION = YES; 515 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 516 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 517 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 518 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 519 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 520 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 521 | CLANG_WARN_STRICT_PROTOTYPES = YES; 522 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 523 | CLANG_WARN_UNREACHABLE_CODE = YES; 524 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 525 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 526 | COPY_PHASE_STRIP = NO; 527 | ENABLE_STRICT_OBJC_MSGSEND = YES; 528 | ENABLE_TESTABILITY = YES; 529 | "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64 "; 530 | GCC_C_LANGUAGE_STANDARD = gnu99; 531 | GCC_DYNAMIC_NO_PIC = NO; 532 | GCC_NO_COMMON_BLOCKS = YES; 533 | GCC_OPTIMIZATION_LEVEL = 0; 534 | GCC_PREPROCESSOR_DEFINITIONS = ( 535 | "DEBUG=1", 536 | "$(inherited)", 537 | ); 538 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 539 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 540 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 541 | GCC_WARN_UNDECLARED_SELECTOR = YES; 542 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 543 | GCC_WARN_UNUSED_FUNCTION = YES; 544 | GCC_WARN_UNUSED_VARIABLE = YES; 545 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 546 | LD_RUNPATH_SEARCH_PATHS = ( 547 | /usr/lib/swift, 548 | "$(inherited)", 549 | ); 550 | LIBRARY_SEARCH_PATHS = ( 551 | "\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"", 552 | "\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"", 553 | "\"$(inherited)\"", 554 | ); 555 | MTL_ENABLE_DEBUG_INFO = YES; 556 | ONLY_ACTIVE_ARCH = YES; 557 | SDKROOT = iphoneos; 558 | }; 559 | name = Debug; 560 | }; 561 | 83CBBA211A601CBA00E9B192 /* Release */ = { 562 | isa = XCBuildConfiguration; 563 | buildSettings = { 564 | ALWAYS_SEARCH_USER_PATHS = NO; 565 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 566 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 567 | CLANG_CXX_LIBRARY = "libc++"; 568 | CLANG_ENABLE_MODULES = YES; 569 | CLANG_ENABLE_OBJC_ARC = YES; 570 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 571 | CLANG_WARN_BOOL_CONVERSION = YES; 572 | CLANG_WARN_COMMA = YES; 573 | CLANG_WARN_CONSTANT_CONVERSION = YES; 574 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 575 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 576 | CLANG_WARN_EMPTY_BODY = YES; 577 | CLANG_WARN_ENUM_CONVERSION = YES; 578 | CLANG_WARN_INFINITE_RECURSION = YES; 579 | CLANG_WARN_INT_CONVERSION = YES; 580 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 581 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 582 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 583 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 584 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 585 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 586 | CLANG_WARN_STRICT_PROTOTYPES = YES; 587 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 588 | CLANG_WARN_UNREACHABLE_CODE = YES; 589 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 590 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 591 | COPY_PHASE_STRIP = YES; 592 | ENABLE_NS_ASSERTIONS = NO; 593 | ENABLE_STRICT_OBJC_MSGSEND = YES; 594 | "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64 "; 595 | GCC_C_LANGUAGE_STANDARD = gnu99; 596 | GCC_NO_COMMON_BLOCKS = YES; 597 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 598 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 599 | GCC_WARN_UNDECLARED_SELECTOR = YES; 600 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 601 | GCC_WARN_UNUSED_FUNCTION = YES; 602 | GCC_WARN_UNUSED_VARIABLE = YES; 603 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 604 | LD_RUNPATH_SEARCH_PATHS = ( 605 | /usr/lib/swift, 606 | "$(inherited)", 607 | ); 608 | LIBRARY_SEARCH_PATHS = ( 609 | "\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"", 610 | "\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"", 611 | "\"$(inherited)\"", 612 | ); 613 | MTL_ENABLE_DEBUG_INFO = NO; 614 | SDKROOT = iphoneos; 615 | VALIDATE_PRODUCT = YES; 616 | }; 617 | name = Release; 618 | }; 619 | /* End XCBuildConfiguration section */ 620 | 621 | /* Begin XCConfigurationList section */ 622 | 00E357021AD99517003FC87E /* Build configuration list for PBXNativeTarget "exampleTests" */ = { 623 | isa = XCConfigurationList; 624 | buildConfigurations = ( 625 | 00E356F61AD99517003FC87E /* Debug */, 626 | 00E356F71AD99517003FC87E /* Release */, 627 | ); 628 | defaultConfigurationIsVisible = 0; 629 | defaultConfigurationName = Release; 630 | }; 631 | 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "example" */ = { 632 | isa = XCConfigurationList; 633 | buildConfigurations = ( 634 | 13B07F941A680F5B00A75B9A /* Debug */, 635 | 13B07F951A680F5B00A75B9A /* Release */, 636 | ); 637 | defaultConfigurationIsVisible = 0; 638 | defaultConfigurationName = Release; 639 | }; 640 | 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "example" */ = { 641 | isa = XCConfigurationList; 642 | buildConfigurations = ( 643 | 83CBBA201A601CBA00E9B192 /* Debug */, 644 | 83CBBA211A601CBA00E9B192 /* Release */, 645 | ); 646 | defaultConfigurationIsVisible = 0; 647 | defaultConfigurationName = Release; 648 | }; 649 | /* End XCConfigurationList section */ 650 | }; 651 | rootObject = 83CBB9F71A601CBA00E9B192 /* Project object */; 652 | } 653 | -------------------------------------------------------------------------------- /example/ios/example.xcodeproj/xcshareddata/xcschemes/example.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 53 | 55 | 61 | 62 | 63 | 64 | 70 | 72 | 78 | 79 | 80 | 81 | 83 | 84 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /example/ios/example.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/ios/example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /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 | 7 | @implementation AppDelegate 8 | 9 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 10 | { 11 | #ifdef FB_SONARKIT_ENABLED 12 | InitializeFlipper(application); 13 | #endif 14 | 15 | RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; 16 | RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge 17 | moduleName:@"example" 18 | initialProperties:nil]; 19 | 20 | if (@available(iOS 13.0, *)) { 21 | rootView.backgroundColor = [UIColor systemBackgroundColor]; 22 | } else { 23 | rootView.backgroundColor = [UIColor whiteColor]; 24 | } 25 | 26 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 27 | UIViewController *rootViewController = [UIViewController new]; 28 | rootViewController.view = rootView; 29 | self.window.rootViewController = rootViewController; 30 | [self.window makeKeyAndVisible]; 31 | return YES; 32 | } 33 | 34 | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge 35 | { 36 | #if DEBUG 37 | return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; 38 | #else 39 | return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; 40 | #endif 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /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 | Toolkit 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 | NSExceptionDomains 30 | 31 | localhost 32 | 33 | NSExceptionAllowsInsecureHTTPLoads 34 | 35 | 36 | 37 | 38 | NSLocationWhenInUseUsageDescription 39 | 40 | UILaunchStoryboardName 41 | LaunchScreen 42 | UIRequiredDeviceCapabilities 43 | 44 | armv7 45 | 46 | UISupportedInterfaceOrientations 47 | 48 | UIInterfaceOrientationPortrait 49 | UIInterfaceOrientationLandscapeLeft 50 | UIInterfaceOrientationLandscapeRight 51 | 52 | UIViewControllerBasedStatusBarAppearance 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /example/ios/example/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 24 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /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 | /** 2 | * Metro configuration for React Native 3 | * https://github.com/facebook/react-native 4 | * 5 | * @format 6 | */ 7 | 8 | module.exports = { 9 | transformer: { 10 | getTransformOptions: async () => ({ 11 | transform: { 12 | experimentalImportSupport: false, 13 | inlineRequires: true, 14 | }, 15 | }), 16 | }, 17 | }; 18 | -------------------------------------------------------------------------------- /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": "cd android && ./gradlew clean" 12 | }, 13 | "dependencies": { 14 | "react": "17.0.1", 15 | "react-native": "0.64.0", 16 | "react-native-utils-toolkit": "file:../" 17 | }, 18 | "devDependencies": { 19 | "@babel/core": "^7.13.14", 20 | "@babel/runtime": "^7.13.10", 21 | "@react-native-community/eslint-config": "^2.0.0", 22 | "babel-jest": "^26.6.3", 23 | "eslint": "^7.23.0", 24 | "jest": "^26.6.3", 25 | "metro-react-native-babel-preset": "^0.65.2", 26 | "react-test-renderer": "17.0.1" 27 | }, 28 | "jest": { 29 | "preset": "react-native" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /index.ts: -------------------------------------------------------------------------------- 1 | import useScale from './toolkit/ueScale'; 2 | import useDetectDevice from './toolkit/useDetectDevice'; 3 | import { useDeviceOrientation } from './toolkit/useDeviceOrientation'; 4 | import useBackHandler from './toolkit/useBackHandler'; 5 | import useAppState from './toolkit/useAppState'; 6 | import useValidation from './toolkit/useValidation'; 7 | import useArray from './toolkit/useArray'; 8 | 9 | const { 10 | deviceInch, 11 | hasNotch, 12 | height, 13 | isAndroid, 14 | isIOS, 15 | isSmallDevice, 16 | isTablet, 17 | width 18 | } = useDetectDevice; 19 | 20 | const { fontScale, scale } = useScale; 21 | 22 | export { 23 | useDetectDevice, 24 | useScale, 25 | useDeviceOrientation, 26 | useBackHandler, 27 | useAppState, 28 | useValidation, 29 | useArray, 30 | deviceInch, 31 | hasNotch, 32 | height, 33 | isAndroid, 34 | isIOS, 35 | isSmallDevice, 36 | isTablet, 37 | width, 38 | fontScale, 39 | scale, 40 | 41 | }; 42 | -------------------------------------------------------------------------------- /ios/UtilsToolkit.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface UtilsToolkit : NSObject 4 | 5 | @end 6 | -------------------------------------------------------------------------------- /ios/UtilsToolkit.m: -------------------------------------------------------------------------------- 1 | #import "UtilsToolkit.h" 2 | 3 | @implementation UtilsToolkit 4 | 5 | RCT_EXPORT_MODULE() 6 | 7 | - (NSDictionary *)constantsToExport 8 | { 9 | return @{ 10 | @"checkTablet": @([self isTablet]), 11 | @"checkSmallDevice": @([self isSmallDevice]), 12 | @"deviceInch": @([self deviceInch]), 13 | @"checkhasNotch": @([self hasNotch]), 14 | }; 15 | } 16 | 17 | + (BOOL)requiresMainQueueSetup 18 | { 19 | return YES; 20 | } 21 | 22 | - (BOOL) isTablet 23 | { 24 | // TODO: Implement some actually useful functionality 25 | if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) 26 | { 27 | return YES; /* Device is iPad */ 28 | }else{ 29 | return NO; 30 | } 31 | 32 | } 33 | 34 | - (BOOL) isSmallDevice 35 | { 36 | float diagonal = [self deviceInch]; 37 | 38 | if(diagonal < 4.8){ 39 | return YES; 40 | }else{ 41 | return NO; 42 | } 43 | } 44 | 45 | - (float) deviceInch 46 | { 47 | float scale = [[UIScreen mainScreen] scale]; 48 | 49 | NSInteger width = [[UIScreen mainScreen] bounds].size.width; 50 | NSInteger height = [[UIScreen mainScreen] bounds].size.height; 51 | 52 | NSInteger screenHeight = MAX(width, height); 53 | 54 | switch (screenHeight) { 55 | case 240: 56 | return 3.5; 57 | case 480: 58 | return 3.5; 59 | case 568: 60 | return 4; 61 | case 667: 62 | return scale == 3.0 ? 5.5 : 4.7; 63 | case 736: 64 | return 5.5; 65 | case 812: 66 | return 5.4; 67 | case 844: 68 | return 6.1; 69 | case 896: 70 | return 6.5; 71 | case 926: 72 | return 6.7; 73 | case 1024: 74 | return 9.7; 75 | case 1080: 76 | return 10.2; 77 | case 1112: 78 | return 10.5; 79 | case 1180: 80 | return 10.9; 81 | case 1194: 82 | return 11; 83 | case 1366: 84 | return 12.9; 85 | default: 86 | return 0; 87 | } 88 | } 89 | 90 | - (BOOL) hasNotch 91 | { 92 | if (@available(iOS 13.0, *)) { 93 | if([self keyWindow].safeAreaInsets.top > 20.0){ 94 | return YES; 95 | }else { 96 | return NO; 97 | } 98 | 99 | }else{ 100 | if (@available(iOS 11.0, *)) { 101 | if([[[UIApplication sharedApplication] delegate] window].safeAreaInsets.top > 20.0){ 102 | return YES; 103 | }else { 104 | return NO; 105 | } 106 | } else { 107 | // Fallback on earlier versions 108 | return NO; 109 | } 110 | 111 | } 112 | } 113 | 114 | - (UIWindow*)keyWindow { 115 | UIWindow *foundWindow = nil; 116 | NSArray *windows = [[UIApplication sharedApplication]windows]; 117 | for (UIWindow *window in windows) { 118 | if (window.isKeyWindow) { 119 | foundWindow = window; 120 | break; 121 | } 122 | } 123 | return foundWindow; 124 | } 125 | 126 | @end 127 | -------------------------------------------------------------------------------- /ios/UtilsToolkit.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXCopyFilesBuildPhase section */ 10 | 58B511D91A9E6C8500147676 /* CopyFiles */ = { 11 | isa = PBXCopyFilesBuildPhase; 12 | buildActionMask = 2147483647; 13 | dstPath = "include/$(PRODUCT_NAME)"; 14 | dstSubfolderSpec = 16; 15 | files = ( 16 | ); 17 | runOnlyForDeploymentPostprocessing = 0; 18 | }; 19 | /* End PBXCopyFilesBuildPhase section */ 20 | 21 | /* Begin PBXFileReference section */ 22 | 134814201AA4EA6300B7C361 /* libUtilsToolkit.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libUtilsToolkit.a; sourceTree = BUILT_PRODUCTS_DIR; }; 23 | /* End PBXFileReference section */ 24 | 25 | /* Begin PBXFrameworksBuildPhase section */ 26 | 58B511D81A9E6C8500147676 /* Frameworks */ = { 27 | isa = PBXFrameworksBuildPhase; 28 | buildActionMask = 2147483647; 29 | files = ( 30 | ); 31 | runOnlyForDeploymentPostprocessing = 0; 32 | }; 33 | /* End PBXFrameworksBuildPhase section */ 34 | 35 | /* Begin PBXGroup section */ 36 | 134814211AA4EA7D00B7C361 /* Products */ = { 37 | isa = PBXGroup; 38 | children = ( 39 | 134814201AA4EA6300B7C361 /* libUtilsToolkit.a */, 40 | ); 41 | name = Products; 42 | sourceTree = ""; 43 | }; 44 | 58B511D21A9E6C8500147676 = { 45 | isa = PBXGroup; 46 | children = ( 47 | 134814211AA4EA7D00B7C361 /* Products */, 48 | ); 49 | sourceTree = ""; 50 | }; 51 | /* End PBXGroup section */ 52 | 53 | /* Begin PBXNativeTarget section */ 54 | 58B511DA1A9E6C8500147676 /* UtilsToolkit */ = { 55 | isa = PBXNativeTarget; 56 | buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "UtilsToolkit" */; 57 | buildPhases = ( 58 | 58B511D71A9E6C8500147676 /* Sources */, 59 | 58B511D81A9E6C8500147676 /* Frameworks */, 60 | 58B511D91A9E6C8500147676 /* CopyFiles */, 61 | ); 62 | buildRules = ( 63 | ); 64 | dependencies = ( 65 | ); 66 | name = UtilsToolkit; 67 | productName = RCTDataManager; 68 | productReference = 134814201AA4EA6300B7C361 /* libUtilsToolkit.a */; 69 | productType = "com.apple.product-type.library.static"; 70 | }; 71 | /* End PBXNativeTarget section */ 72 | 73 | /* Begin PBXProject section */ 74 | 58B511D31A9E6C8500147676 /* Project object */ = { 75 | isa = PBXProject; 76 | attributes = { 77 | LastUpgradeCheck = 0920; 78 | ORGANIZATIONNAME = Facebook; 79 | TargetAttributes = { 80 | 58B511DA1A9E6C8500147676 = { 81 | CreatedOnToolsVersion = 6.1.1; 82 | }; 83 | }; 84 | }; 85 | buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "UtilsToolkit" */; 86 | compatibilityVersion = "Xcode 3.2"; 87 | developmentRegion = en; 88 | hasScannedForEncodings = 0; 89 | knownRegions = ( 90 | en, 91 | Base, 92 | ); 93 | mainGroup = 58B511D21A9E6C8500147676; 94 | productRefGroup = 58B511D21A9E6C8500147676; 95 | projectDirPath = ""; 96 | projectRoot = ""; 97 | targets = ( 98 | 58B511DA1A9E6C8500147676 /* UtilsToolkit */, 99 | ); 100 | }; 101 | /* End PBXProject section */ 102 | 103 | /* Begin PBXSourcesBuildPhase section */ 104 | 58B511D71A9E6C8500147676 /* Sources */ = { 105 | isa = PBXSourcesBuildPhase; 106 | buildActionMask = 2147483647; 107 | files = ( 108 | ); 109 | runOnlyForDeploymentPostprocessing = 0; 110 | }; 111 | /* End PBXSourcesBuildPhase section */ 112 | 113 | /* Begin XCBuildConfiguration section */ 114 | 58B511ED1A9E6C8500147676 /* Debug */ = { 115 | isa = XCBuildConfiguration; 116 | buildSettings = { 117 | ALWAYS_SEARCH_USER_PATHS = NO; 118 | CLANG_ANALYZER_NONNULL = YES; 119 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 120 | CLANG_CXX_LIBRARY = "libc++"; 121 | CLANG_ENABLE_MODULES = YES; 122 | CLANG_ENABLE_OBJC_ARC = YES; 123 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 124 | CLANG_WARN_BOOL_CONVERSION = YES; 125 | CLANG_WARN_COMMA = YES; 126 | CLANG_WARN_CONSTANT_CONVERSION = YES; 127 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 128 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 129 | CLANG_WARN_EMPTY_BODY = YES; 130 | CLANG_WARN_ENUM_CONVERSION = YES; 131 | CLANG_WARN_INFINITE_RECURSION = YES; 132 | CLANG_WARN_INT_CONVERSION = YES; 133 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 134 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 135 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 136 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 137 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 138 | CLANG_WARN_STRICT_PROTOTYPES = YES; 139 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 140 | CLANG_WARN_UNREACHABLE_CODE = YES; 141 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 142 | COPY_PHASE_STRIP = NO; 143 | ENABLE_STRICT_OBJC_MSGSEND = YES; 144 | ENABLE_TESTABILITY = YES; 145 | GCC_C_LANGUAGE_STANDARD = gnu99; 146 | GCC_DYNAMIC_NO_PIC = NO; 147 | GCC_NO_COMMON_BLOCKS = YES; 148 | GCC_OPTIMIZATION_LEVEL = 0; 149 | GCC_PREPROCESSOR_DEFINITIONS = ( 150 | "DEBUG=1", 151 | "$(inherited)", 152 | ); 153 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 154 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 155 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 156 | GCC_WARN_UNDECLARED_SELECTOR = YES; 157 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 158 | GCC_WARN_UNUSED_FUNCTION = YES; 159 | GCC_WARN_UNUSED_VARIABLE = YES; 160 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 161 | LD_RUNPATH_SEARCH_PATHS = "/usr/lib/swift $(inherited)"; 162 | LIBRARY_SEARCH_PATHS = ( 163 | "\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"", 164 | "\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"", 165 | "\"$(inherited)\"", 166 | ); 167 | MTL_ENABLE_DEBUG_INFO = YES; 168 | ONLY_ACTIVE_ARCH = YES; 169 | SDKROOT = iphoneos; 170 | }; 171 | name = Debug; 172 | }; 173 | 58B511EE1A9E6C8500147676 /* Release */ = { 174 | isa = XCBuildConfiguration; 175 | buildSettings = { 176 | ALWAYS_SEARCH_USER_PATHS = NO; 177 | CLANG_ANALYZER_NONNULL = YES; 178 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 179 | CLANG_CXX_LIBRARY = "libc++"; 180 | CLANG_ENABLE_MODULES = YES; 181 | CLANG_ENABLE_OBJC_ARC = YES; 182 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 183 | CLANG_WARN_BOOL_CONVERSION = YES; 184 | CLANG_WARN_COMMA = YES; 185 | CLANG_WARN_CONSTANT_CONVERSION = YES; 186 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 187 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 188 | CLANG_WARN_EMPTY_BODY = YES; 189 | CLANG_WARN_ENUM_CONVERSION = YES; 190 | CLANG_WARN_INFINITE_RECURSION = YES; 191 | CLANG_WARN_INT_CONVERSION = YES; 192 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 193 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 194 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 195 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 196 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 197 | CLANG_WARN_STRICT_PROTOTYPES = YES; 198 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 199 | CLANG_WARN_UNREACHABLE_CODE = YES; 200 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 201 | COPY_PHASE_STRIP = YES; 202 | ENABLE_NS_ASSERTIONS = NO; 203 | ENABLE_STRICT_OBJC_MSGSEND = YES; 204 | GCC_C_LANGUAGE_STANDARD = gnu99; 205 | GCC_NO_COMMON_BLOCKS = YES; 206 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 207 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 208 | GCC_WARN_UNDECLARED_SELECTOR = YES; 209 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 210 | GCC_WARN_UNUSED_FUNCTION = YES; 211 | GCC_WARN_UNUSED_VARIABLE = YES; 212 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 213 | LD_RUNPATH_SEARCH_PATHS = "/usr/lib/swift $(inherited)"; 214 | LIBRARY_SEARCH_PATHS = ( 215 | "\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"", 216 | "\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"", 217 | "\"$(inherited)\"", 218 | ); 219 | MTL_ENABLE_DEBUG_INFO = NO; 220 | SDKROOT = iphoneos; 221 | VALIDATE_PRODUCT = YES; 222 | }; 223 | name = Release; 224 | }; 225 | 58B511F01A9E6C8500147676 /* Debug */ = { 226 | isa = XCBuildConfiguration; 227 | buildSettings = { 228 | HEADER_SEARCH_PATHS = ( 229 | "$(inherited)", 230 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 231 | "$(SRCROOT)/../../../React/**", 232 | "$(SRCROOT)/../../react-native/React/**", 233 | ); 234 | LIBRARY_SEARCH_PATHS = "$(inherited)"; 235 | OTHER_LDFLAGS = "-ObjC"; 236 | PRODUCT_NAME = UtilsToolkit; 237 | SKIP_INSTALL = YES; 238 | }; 239 | name = Debug; 240 | }; 241 | 58B511F11A9E6C8500147676 /* Release */ = { 242 | isa = XCBuildConfiguration; 243 | buildSettings = { 244 | HEADER_SEARCH_PATHS = ( 245 | "$(inherited)", 246 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 247 | "$(SRCROOT)/../../../React/**", 248 | "$(SRCROOT)/../../react-native/React/**", 249 | ); 250 | LIBRARY_SEARCH_PATHS = "$(inherited)"; 251 | OTHER_LDFLAGS = "-ObjC"; 252 | PRODUCT_NAME = UtilsToolkit; 253 | SKIP_INSTALL = YES; 254 | }; 255 | name = Release; 256 | }; 257 | /* End XCBuildConfiguration section */ 258 | 259 | /* Begin XCConfigurationList section */ 260 | 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "UtilsToolkit" */ = { 261 | isa = XCConfigurationList; 262 | buildConfigurations = ( 263 | 58B511ED1A9E6C8500147676 /* Debug */, 264 | 58B511EE1A9E6C8500147676 /* Release */, 265 | ); 266 | defaultConfigurationIsVisible = 0; 267 | defaultConfigurationName = Release; 268 | }; 269 | 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "UtilsToolkit" */ = { 270 | isa = XCConfigurationList; 271 | buildConfigurations = ( 272 | 58B511F01A9E6C8500147676 /* Debug */, 273 | 58B511F11A9E6C8500147676 /* Release */, 274 | ); 275 | defaultConfigurationIsVisible = 0; 276 | defaultConfigurationName = Release; 277 | }; 278 | /* End XCConfigurationList section */ 279 | }; 280 | rootObject = 58B511D31A9E6C8500147676 /* Project object */; 281 | } 282 | -------------------------------------------------------------------------------- /ios/UtilsToolkit.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /mock.js: -------------------------------------------------------------------------------- 1 | 2 | function NOOP() {} 3 | module.exports = { 4 | useScale: { 5 | scale: NOOP, 6 | fontScale: NOOP, 7 | }, 8 | useDetectDevice: { 9 | isTablet: NOOP, 10 | isSmallDevice: NOOP, 11 | isAndroid: NOOP, 12 | isIOS: NOOP, 13 | hasNotch: NOOP, 14 | deviceInch: NOOP, 15 | width: NOOP, 16 | height: NOOP, 17 | }, 18 | scale: NOOP, 19 | fontScale: NOOP, 20 | isTablet: NOOP, 21 | isSmallDevice: NOOP, 22 | isAndroid: NOOP, 23 | isIOS: NOOP, 24 | hasNotch: NOOP, 25 | deviceInch: NOOP, 26 | width: NOOP, 27 | height: NOOP, 28 | useDeviceOrientation: NOOP, 29 | useBackHandler: NOOP, 30 | useAppState: NOOP, 31 | useValidation: NOOP 32 | } 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-utils-toolkit", 3 | "title": "React Native Utils Toolkit", 4 | "version": "1.6.0", 5 | "description": "Toolkit makes the UI more perfect on many screen sizes.", 6 | "main": "index.ts", 7 | "scripts": { 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/hoaphantn7604/react-native-utils-toolkit.git", 13 | "baseUrl": "https://github.com/hoaphantn7604/react-native-utils-toolkit" 14 | }, 15 | "keywords": [ 16 | "react-native", 17 | "scale", 18 | "scaling", 19 | "size matter", 20 | "size matters", 21 | "check tablet", 22 | "check small device", 23 | "has notch", 24 | "device inch", 25 | "device orientation", 26 | "back handler", 27 | "app state" 28 | ], 29 | "author": { 30 | "name": "Hoa Phan", 31 | "email": "hoaphantn7604@gmail.com" 32 | }, 33 | "license": "MIT", 34 | "licenseFilename": "LICENSE", 35 | "readmeFilename": "README.md", 36 | "devDependencies": { 37 | "react": "*", 38 | "react-native": "*" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /react-native-utils-toolkit.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 = "react-native-utils-toolkit" 7 | s.version = package["version"] 8 | s.summary = package["description"] 9 | s.description = <<-DESC 10 | react-native-utils-toolkit 11 | DESC 12 | s.homepage = "https://github.com/github_account/react-native-utils-toolkit" 13 | # brief license entry: 14 | s.license = "MIT" 15 | # optional - use expanded license entry instead: 16 | # s.license = { :type => "MIT", :file => "LICENSE" } 17 | s.authors = { "Your Name" => "yourname@email.com" } 18 | s.platforms = { :ios => "9.0" } 19 | s.source = { :git => "https://github.com/github_account/react-native-utils-toolkit.git", :tag => "#{s.version}" } 20 | 21 | s.source_files = "ios/**/*.{h,c,m,swift}" 22 | s.requires_arc = true 23 | 24 | s.dependency "React" 25 | # ... 26 | # s.dependency "..." 27 | end 28 | 29 | -------------------------------------------------------------------------------- /toolkit/devicesWithNotch.ts: -------------------------------------------------------------------------------- 1 | 2 | export const devicesWithNotch = [{ 3 | brand: 'Asus', 4 | model: 'ZenFone 5' 5 | }, { 6 | brand: 'Asus', 7 | model: 'ZenFone 5z' 8 | }, { 9 | brand: 'google', 10 | model: 'Pixel 3 XL' 11 | }, { 12 | brand: 'google', 13 | model: 'Pixel 3a' 14 | }, { 15 | brand: 'google', 16 | model: 'Pixel 4a' 17 | }, { 18 | brand: 'Huawei', 19 | model: 'P20' 20 | }, { 21 | brand: 'Huawei', 22 | model: 'P20 Plus' 23 | }, { 24 | brand: 'Huawei', 25 | model: 'P20 Lite' 26 | }, { 27 | brand: 'Huawei', 28 | model: 'ANE-LX1' 29 | }, { 30 | brand: 'Huawei', 31 | model: 'INE-LX1' 32 | }, { 33 | brand: 'Huawei', 34 | model: 'POT-LX1' 35 | }, { 36 | brand: 'Huawei', 37 | model: 'Honor 10' 38 | }, { 39 | brand: 'Huawei', 40 | model: 'Mate 20 Lite' 41 | }, { 42 | brand: 'Huawei', 43 | model: 'Mate 20 Pro' 44 | }, { 45 | brand: 'Huawei', 46 | model: 'ELE-L29' // P30 47 | 48 | }, { 49 | brand: 'Huawei', 50 | model: 'P30 Lite' 51 | }, { 52 | brand: 'Huawei', 53 | model: 'P30 Pro' 54 | }, { 55 | brand: 'Huawei', 56 | model: 'Nova 3' 57 | }, { 58 | brand: 'Huawei', 59 | model: 'Nova 3i' 60 | }, { 61 | brand: 'Leagoo', 62 | model: 'S9' 63 | }, { 64 | brand: 'LG', 65 | model: 'G7' 66 | }, { 67 | brand: 'LG', 68 | model: 'G7 ThinQ' 69 | }, { 70 | brand: 'LG', 71 | model: 'G7+ ThinQ' 72 | }, { 73 | brand: 'LG', 74 | model: 'LM-Q910' //G7 One 75 | 76 | }, { 77 | brand: 'LG', 78 | model: 'LM-G710' //G7 ThinQ 79 | 80 | }, { 81 | brand: 'LG', 82 | model: 'LM-V405' //V40 ThinQ 83 | 84 | }, { 85 | brand: 'Motorola', 86 | model: 'Moto g7 Play' 87 | }, { 88 | brand: 'Motorola', 89 | model: 'Moto g7 Power' 90 | }, { 91 | brand: 'Motorola', 92 | model: 'One' 93 | }, { 94 | brand: 'Motorola', 95 | model: 'Motorola One Vision' 96 | }, { 97 | brand: 'Nokia', 98 | model: '5.1 Plus' 99 | }, { 100 | brand: 'Nokia', 101 | model: 'Nokia 6.1 Plus' 102 | }, { 103 | brand: 'Nokia', 104 | model: '7.1' 105 | }, { 106 | brand: 'Nokia', 107 | model: '8.1' 108 | }, { 109 | brand: 'OnePlus', 110 | model: '6' 111 | }, { 112 | brand: 'OnePlus', 113 | model: 'A6003' 114 | }, { 115 | brand: 'ONEPLUS', 116 | model: 'A6000' 117 | }, { 118 | brand: 'OnePlus', 119 | model: 'OnePlus A6003' 120 | }, { 121 | brand: 'OnePlus', 122 | model: 'ONEPLUS A6010' 123 | }, { 124 | brand: 'OnePlus', 125 | model: 'ONEPLUS A6013' 126 | }, { 127 | brand: 'OnePlus', 128 | model: 'ONEPLUS A6000' 129 | }, { 130 | brand: 'Oppo', 131 | model: 'R15' 132 | }, { 133 | brand: 'Oppo', 134 | model: 'R15 Pro' 135 | }, { 136 | brand: 'Oppo', 137 | model: 'F7' 138 | }, { 139 | brand: 'Oukitel', 140 | model: 'U18' 141 | }, { 142 | brand: 'Redmi', 143 | model: 'M2004J19C' 144 | }, { 145 | brand: 'Sharp', 146 | model: 'Aquos S3' 147 | }, { 148 | brand: 'Vivo', 149 | model: 'V9' 150 | }, { 151 | brand: 'Vivo', 152 | model: 'X21' 153 | }, { 154 | brand: 'Vivo', 155 | model: 'X21 UD' 156 | }, { 157 | brand: 'xiaomi', 158 | model: 'MI 8' 159 | }, { 160 | brand: 'xiaomi', 161 | model: 'MI 8 Explorer Edition' 162 | }, { 163 | brand: 'xiaomi', 164 | model: 'MI 8 SE' 165 | }, { 166 | brand: 'xiaomi', 167 | model: 'MI 8 UD' 168 | }, { 169 | brand: 'xiaomi', 170 | model: 'MI 8 Lite' 171 | }, { 172 | brand: 'xiaomi', 173 | model: 'Mi 9' 174 | }, { 175 | brand: 'xiaomi', 176 | model: 'POCO F1' 177 | }, { 178 | brand: 'xiaomi', 179 | model: 'POCOPHONE F1' 180 | }, { 181 | brand: 'xiaomi', 182 | model: 'Redmi 6 Pro' 183 | }, { 184 | brand: 'xiaomi', 185 | model: 'Redmi Note 7' 186 | }, { 187 | brand: 'xiaomi', 188 | model: 'Redmi 7' 189 | }, { 190 | brand: 'xiaomi', 191 | model: 'Redmi Note 8' 192 | }, { 193 | brand: 'xiaomi', 194 | model: 'Mi A2 Lite' 195 | }, { 196 | brand: 'Blackview', 197 | model: 'A30' 198 | }, { 199 | brand: 'Samsung', 200 | model: 'SM-A217F' 201 | }, { 202 | brand: 'Google', 203 | model: 'sdk_gphone_x86_arm' 204 | }]; -------------------------------------------------------------------------------- /toolkit/model.ts: -------------------------------------------------------------------------------- 1 | export interface IUseScale { 2 | fontScale: (number: number) => number; 3 | scale: (number: number) => number; 4 | } 5 | 6 | export interface IUseDetectDevice { 7 | isTablet: boolean; 8 | isSmallDevice: boolean; 9 | isAndroid: boolean; 10 | isIOS: boolean; 11 | hasNotch: boolean; 12 | deviceInch: number; 13 | width: number; 14 | height: number; 15 | } -------------------------------------------------------------------------------- /toolkit/ueScale.ts: -------------------------------------------------------------------------------- 1 | import { NativeModules, PixelRatio } from 'react-native'; 2 | import { IUseScale } from './model'; 3 | 4 | const { UtilsToolkit } = NativeModules; 5 | const { 6 | deviceInch 7 | } = UtilsToolkit.getConstants(); 8 | 9 | 10 | const pixelDensity = PixelRatio.get(); 11 | 12 | const useScale: IUseScale = { 13 | fontScale: (number: number = 1) => { 14 | const value = (deviceInch + pixelDensity) / 10; 15 | const scale = number * Number(value.toFixed(1)); 16 | return scale; 17 | }, 18 | scale: (number: number = 1) => { 19 | const value = (deviceInch + (pixelDensity + 0.5)) / 10; 20 | const scale = number * Number(value.toFixed(1)); 21 | return scale; 22 | }, 23 | }; 24 | 25 | 26 | export default useScale; 27 | -------------------------------------------------------------------------------- /toolkit/useAppState.ts: -------------------------------------------------------------------------------- 1 | import { DependencyList, useEffect } from 'react'; 2 | import { AppState } from 'react-native'; 3 | 4 | function useAppState(effect: (state: string) => void, deps?: DependencyList) { 5 | useEffect(() => { 6 | const susbcription = AppState.addEventListener('change', effect); 7 | return () => { 8 | // @ts-expect-error - React Native >= 0.65 9 | if (typeof susbcription?.remove === 'function') { 10 | // @ts-expect-error - need update @types/react-native@0.65.x 11 | susbcription.remove(); 12 | } else { 13 | AppState.removeEventListener('change', effect); 14 | } 15 | }; 16 | }, deps); 17 | } 18 | 19 | export default useAppState; 20 | -------------------------------------------------------------------------------- /toolkit/useArray.ts: -------------------------------------------------------------------------------- 1 | const useArray = { 2 | excludeDuplicate: (arr1: any[], arr2: any[]) => { 3 | if (arr1.length > arr2.length) { 4 | return arr1.filter(item => !arr2.includes(item)); 5 | } else { 6 | return arr2.filter(item => !arr1.includes(item)); 7 | } 8 | } 9 | }; 10 | 11 | export default useArray; -------------------------------------------------------------------------------- /toolkit/useBackHandler.ts: -------------------------------------------------------------------------------- 1 | import { DependencyList, EffectCallback, useEffect } from 'react'; 2 | import { BackHandler } from 'react-native'; 3 | 4 | function useBackHandler(effect: EffectCallback, deps?: DependencyList) { 5 | useEffect(() => { 6 | const susbcription = BackHandler.addEventListener('hardwareBackPress', () => { 7 | effect(); 8 | return true; 9 | }) 10 | return () => { 11 | if (typeof susbcription?.remove === 'function') { 12 | susbcription.remove(); 13 | } else { 14 | BackHandler.removeEventListener('hardwareBackPress', () => { 15 | effect(); 16 | return true; 17 | }); 18 | } 19 | }; 20 | }, deps); 21 | } 22 | 23 | export default useBackHandler; -------------------------------------------------------------------------------- /toolkit/useDetectDevice.ts: -------------------------------------------------------------------------------- 1 | import { Dimensions, NativeModules, Platform, PixelRatio } from 'react-native'; 2 | import { devicesWithNotch } from './devicesWithNotch'; 3 | import { IUseDetectDevice } from './model'; 4 | 5 | const { width, height } = Dimensions.get('window'); 6 | const { UtilsToolkit } = NativeModules; 7 | const { checkSmallDevice, 8 | checkhasNotch, getModel, getBrand, 9 | deviceInch 10 | } = UtilsToolkit.getConstants(); 11 | 12 | const isTablet = () => { 13 | let pixelDensity = PixelRatio.get(); 14 | const adjustedWidth = width * pixelDensity; 15 | const adjustedHeight = height * pixelDensity; 16 | if (pixelDensity < 2 && (adjustedWidth >= 1000 || adjustedHeight >= 1000)) { 17 | return true; 18 | } else { 19 | return ( 20 | pixelDensity === 2 && (adjustedWidth >= 1920 || adjustedHeight >= 1920) 21 | ); 22 | } 23 | }; 24 | 25 | const hasNotch = () => { 26 | if (Platform.OS === 'ios') { 27 | if (isTablet()) { 28 | return false; 29 | } else { 30 | return checkhasNotch; 31 | } 32 | } else { 33 | const model = getModel; 34 | const brand = getBrand; 35 | 36 | const notch = devicesWithNotch.findIndex(item => item.brand.toLowerCase() === brand.toLowerCase() && item.model.toLowerCase() === model.toLowerCase()) !== -1; 37 | return notch; 38 | } 39 | } 40 | 41 | const useDetectDevice: IUseDetectDevice = { 42 | isTablet: isTablet(), 43 | isSmallDevice: checkSmallDevice, 44 | isAndroid: Platform.OS === 'android', 45 | isIOS: Platform.OS === 'ios', 46 | hasNotch: hasNotch(), 47 | deviceInch: Number(deviceInch.toFixed(1)), 48 | width: Dimensions.get('window').width, 49 | height: Dimensions.get('window').height, 50 | } 51 | 52 | export default useDetectDevice; 53 | -------------------------------------------------------------------------------- /toolkit/useDeviceOrientation.ts: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from 'react' 2 | import { Dimensions, ScaledSize } from 'react-native' 3 | 4 | const isOrientationPortrait = ({ width, height }: ScaledSize) => height >= width 5 | const isOrientationLandscape = ({ width, height }: ScaledSize) => width >= height 6 | 7 | export function useDeviceOrientation() { 8 | const screen = Dimensions.get('screen') 9 | const initialState = { 10 | portrait: isOrientationPortrait(screen), 11 | landscape: isOrientationLandscape(screen), 12 | } 13 | 14 | const [orientation, setOrientation] = useState(initialState) 15 | 16 | useEffect(() => { 17 | const onChange = ({ screen }: { screen: ScaledSize }) => { 18 | setOrientation({ 19 | portrait: isOrientationPortrait(screen), 20 | landscape: isOrientationLandscape(screen), 21 | }) 22 | } 23 | 24 | const subscription = Dimensions.addEventListener('change', onChange) 25 | 26 | return () => { 27 | // @ts-expect-error - React Native >= 0.65 28 | if (typeof subscription?.remove === 'function') { 29 | // @ts-expect-error - need update @types/react-native@0.65.x 30 | subscription.remove() 31 | } else { 32 | // React Native < 0.65 33 | Dimensions.removeEventListener('change', onChange) 34 | } 35 | } 36 | }, []) 37 | 38 | return orientation.portrait === true ? 'PORTRAIT' : 'LANDSCAPE'; 39 | } 40 | -------------------------------------------------------------------------------- /toolkit/useValidation.ts: -------------------------------------------------------------------------------- 1 | const useValidation = { 2 | validateEmail: (str: string) => { 3 | const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; 4 | return re.test(String(str).toLowerCase()); 5 | }, 6 | validateUsername: (str: string) => { 7 | const re = /^[a-zA-Z0-9-]{6,12}$/; 8 | return re.test(str); 9 | }, 10 | validatePassword: (str: string) => { 11 | const re = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,20}$/; 12 | return re.test(str); 13 | }, 14 | validateUppercase: (str: string) => { 15 | const re = /^[A-Z]/g; 16 | return re.test(str); 17 | }, 18 | validateLowercase: (str: string) => { 19 | const re = /[a-z]/g; 20 | return re.test(str); 21 | }, 22 | validateSpecial: (str: string) => { 23 | const re = /^(?=.*[@$!%*?&])[0-9A-Za-z\d@$!%*?&]{0,}$/; 24 | return re.test(str); 25 | }, 26 | validateString: (value: any) => { 27 | return typeof value === 'string'; 28 | }, 29 | validateNumer: (value: any) => { 30 | return typeof value === 'number'; 31 | }, 32 | validateObject: (value: any) => { 33 | return typeof value === 'object'; 34 | }, 35 | validateArray: (value: any) => { 36 | return Array.isArray(value); 37 | }, 38 | isRequired: (value: any) => { 39 | if (value) { 40 | if (typeof value === 'object') { 41 | return Object.keys(value).length > 0; 42 | } 43 | if (Array.isArray(value)) { 44 | return value.length > 0; 45 | } 46 | return true; 47 | } 48 | return false; 49 | }, 50 | validateConsecutiveNumber: (arr: any[]) => { 51 | const differenceAry = arr.slice(1).map((n: any, i: number) => { 52 | return n - arr[i]; 53 | }); 54 | const isDifference = differenceAry.every(value => value === 1); 55 | 56 | return isDifference; 57 | }, 58 | validateSameValue: (arr: string[]) => { 59 | return arr.filter((item, index) => arr.indexOf(item) !== index).length === arr.length - 1; 60 | } 61 | } 62 | export default useValidation; 63 | --------------------------------------------------------------------------------