├── .gitattributes
├── .babelrc
├── app.json
├── android
├── settings.gradle
├── app
│ ├── src
│ │ └── main
│ │ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ └── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── blogpost
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── MainApplication.java
│ │ │ └── AndroidManifest.xml
│ ├── BUCK
│ ├── proguard-rules.pro
│ └── build.gradle
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── keystores
│ ├── debug.keystore.properties
│ └── BUCK
├── build.gradle
├── gradle.properties
├── gradlew.bat
└── gradlew
├── images
├── meme.jpg
├── iphone1.png
├── tablet1.png
├── iphoneflex.png
├── tabletflex.png
├── iphonescaling.png
├── iphoneviewport.png
├── tabletscaling.png
└── tabletviewport.png
├── index.ios.js
├── index.android.js
├── pages
├── App.js
├── scaling.js
├── contants.js
├── Example.js
├── ViewPortExample.js
├── FlexExample.js
└── ScalingExample.js
├── ios
├── BlogPost
│ ├── AppDelegate.h
│ ├── main.m
│ ├── Images.xcassets
│ │ └── AppIcon.appiconset
│ │ │ └── Contents.json
│ ├── AppDelegate.m
│ ├── Info.plist
│ └── Base.lproj
│ │ └── LaunchScreen.xib
└── BlogPost.xcodeproj
│ ├── xcshareddata
│ └── xcschemes
│ │ ├── BlogPost.xcscheme
│ │ └── BlogPost-tvOS.xcscheme
│ └── project.pbxproj
├── package.json
├── .gitignore
├── .flowconfig
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.pbxproj -text
2 |
--------------------------------------------------------------------------------
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["react-native"]
3 | }
--------------------------------------------------------------------------------
/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "BlogPost",
3 | "displayName": "BlogPost"
4 | }
--------------------------------------------------------------------------------
/android/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'BlogPost'
2 |
3 | include ':app'
4 |
--------------------------------------------------------------------------------
/images/meme.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirsky/react-native-scaling-example/HEAD/images/meme.jpg
--------------------------------------------------------------------------------
/images/iphone1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirsky/react-native-scaling-example/HEAD/images/iphone1.png
--------------------------------------------------------------------------------
/images/tablet1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirsky/react-native-scaling-example/HEAD/images/tablet1.png
--------------------------------------------------------------------------------
/images/iphoneflex.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirsky/react-native-scaling-example/HEAD/images/iphoneflex.png
--------------------------------------------------------------------------------
/images/tabletflex.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirsky/react-native-scaling-example/HEAD/images/tabletflex.png
--------------------------------------------------------------------------------
/images/iphonescaling.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirsky/react-native-scaling-example/HEAD/images/iphonescaling.png
--------------------------------------------------------------------------------
/images/iphoneviewport.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirsky/react-native-scaling-example/HEAD/images/iphoneviewport.png
--------------------------------------------------------------------------------
/images/tabletscaling.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirsky/react-native-scaling-example/HEAD/images/tabletscaling.png
--------------------------------------------------------------------------------
/images/tabletviewport.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirsky/react-native-scaling-example/HEAD/images/tabletviewport.png
--------------------------------------------------------------------------------
/android/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BlogPost
3 |
4 |
--------------------------------------------------------------------------------
/android/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirsky/react-native-scaling-example/HEAD/android/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/android/keystores/debug.keystore.properties:
--------------------------------------------------------------------------------
1 | key.store=debug.keystore
2 | key.alias=androiddebugkey
3 | key.store.password=android
4 | key.alias.password=android
5 |
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirsky/react-native-scaling-example/HEAD/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirsky/react-native-scaling-example/HEAD/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirsky/react-native-scaling-example/HEAD/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirsky/react-native-scaling-example/HEAD/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/keystores/BUCK:
--------------------------------------------------------------------------------
1 | keystore(
2 | name = 'debug',
3 | store = 'debug.keystore',
4 | properties = 'debug.keystore.properties',
5 | visibility = [
6 | 'PUBLIC',
7 | ],
8 | )
9 |
--------------------------------------------------------------------------------
/index.ios.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { AppRegistry } from 'react-native';
3 | import App from './pages/App';
4 |
5 | const BlogPost = () => ;
6 | export default BlogPost;
7 |
8 | AppRegistry.registerComponent('BlogPost', () => BlogPost);
9 |
--------------------------------------------------------------------------------
/android/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | zipStoreBase=GRADLE_USER_HOME
4 | zipStorePath=wrapper/dists
5 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
6 |
--------------------------------------------------------------------------------
/index.android.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { AppRegistry } from 'react-native';
3 | import App from './pages/App';
4 |
5 | const BlogPost = () => ;
6 | export default BlogPost;
7 |
8 | AppRegistry.registerComponent('BlogPost', () => BlogPost);
9 |
--------------------------------------------------------------------------------
/pages/App.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import Example from './Example';
3 | import FlexExample from './FlexExample';
4 | import ViewPortExample from './ViewPortExample';
5 | import ScalingExample from './ScalingExample';
6 |
7 | const App = () => ;
8 |
9 | export default App;
--------------------------------------------------------------------------------
/pages/scaling.js:
--------------------------------------------------------------------------------
1 | import { Dimensions } from 'react-native';
2 | const { width, height } = Dimensions.get('window');
3 |
4 | const scale = size => width / 350 * size;
5 | const verticalScale = size => height / 680 * size;
6 | const moderateScale = (size, factor = 0.5) => size + (scale(size) - size) * factor;
7 |
8 | export {scale, verticalScale, moderateScale};
9 |
--------------------------------------------------------------------------------
/android/app/src/main/java/com/blogpost/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.blogpost;
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.
9 | * This is used to schedule rendering of the component.
10 | */
11 | @Override
12 | protected String getMainComponentName() {
13 | return "BlogPost";
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/pages/contants.js:
--------------------------------------------------------------------------------
1 | export const loremIpsum = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
--------------------------------------------------------------------------------
/ios/BlogPost/AppDelegate.h:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2015-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | */
9 |
10 | #import
11 |
12 | @interface AppDelegate : UIResponder
13 |
14 | @property (nonatomic, strong) UIWindow *window;
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/ios/BlogPost/main.m:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2015-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | */
9 |
10 | #import
11 |
12 | #import "AppDelegate.h"
13 |
14 | int main(int argc, char * argv[]) {
15 | @autoreleasepool {
16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "BlogPost",
3 | "version": "0.0.1",
4 | "private": true,
5 | "scripts": {
6 | "start": "node node_modules/react-native/local-cli/cli.js start",
7 | "test": "jest"
8 | },
9 | "dependencies": {
10 | "react": "15.4.2",
11 | "react-native": "0.41.2",
12 | "react-native-viewport-units": "0.0.5"
13 | },
14 | "devDependencies": {
15 | "babel-jest": "19.0.0",
16 | "babel-preset-react-native": "1.9.1",
17 | "jest": "19.0.0",
18 | "react-test-renderer": "15.4.2"
19 | },
20 | "jest": {
21 | "preset": "react-native"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.3.1'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | mavenLocal()
18 | jcenter()
19 | maven {
20 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
21 | url "$rootDir/../node_modules/react-native/android"
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/ios/BlogPost/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 | }
--------------------------------------------------------------------------------
/android/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 |
20 | android.useDeprecatedNdk=true
21 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # OSX
2 | #
3 | .DS_Store
4 |
5 | # Xcode
6 | #
7 | build/
8 | *.pbxuser
9 | !default.pbxuser
10 | *.mode1v3
11 | !default.mode1v3
12 | *.mode2v3
13 | !default.mode2v3
14 | *.perspectivev3
15 | !default.perspectivev3
16 | xcuserdata
17 | *.xccheckout
18 | *.moved-aside
19 | DerivedData
20 | *.hmap
21 | *.ipa
22 | *.xcuserstate
23 | project.xcworkspace
24 |
25 | # Android/IntelliJ
26 | #
27 | build/
28 | .idea
29 | .gradle
30 | local.properties
31 | *.iml
32 |
33 | # node.js
34 | #
35 | node_modules/
36 | npm-debug.log
37 | yarn-error.log
38 |
39 | # BUCK
40 | buck-out/
41 | \.buckd/
42 | android/app/libs
43 | *.keystore
44 |
45 | # fastlane
46 | #
47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
48 | # screenshots whenever they are needed.
49 | # For more information about the recommended setup visit:
50 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md
51 |
52 | fastlane/report.xml
53 | fastlane/Preview.html
54 | fastlane/screenshots
55 |
--------------------------------------------------------------------------------
/android/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 |
12 |
13 |
19 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/android/app/src/main/java/com/blogpost/MainApplication.java:
--------------------------------------------------------------------------------
1 | package com.blogpost;
2 |
3 | import android.app.Application;
4 | import android.util.Log;
5 |
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.react.shell.MainReactPackage;
11 | import com.facebook.soloader.SoLoader;
12 |
13 | import java.util.Arrays;
14 | import java.util.List;
15 |
16 | public class MainApplication extends Application implements ReactApplication {
17 |
18 | private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
19 | @Override
20 | public boolean getUseDeveloperSupport() {
21 | return BuildConfig.DEBUG;
22 | }
23 |
24 | @Override
25 | protected List getPackages() {
26 | return Arrays.asList(
27 | new MainReactPackage()
28 | );
29 | }
30 | };
31 |
32 | @Override
33 | public ReactNativeHost getReactNativeHost() {
34 | return mReactNativeHost;
35 | }
36 |
37 | @Override
38 | public void onCreate() {
39 | super.onCreate();
40 | SoLoader.init(this, /* native exopackage */ false);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/.flowconfig:
--------------------------------------------------------------------------------
1 | [ignore]
2 | ; We fork some components by platform
3 | .*/*[.]android.js
4 |
5 | ; Ignore "BUCK" generated dirs
6 | /\.buckd/
7 |
8 | ; Ignore unexpected extra "@providesModule"
9 | .*/node_modules/.*/node_modules/fbjs/.*
10 |
11 | ; Ignore duplicate module providers
12 | ; For RN Apps installed via npm, "Libraries" folder is inside
13 | ; "node_modules/react-native" but in the source repo it is in the root
14 | .*/Libraries/react-native/React.js
15 | .*/Libraries/react-native/ReactNative.js
16 |
17 | [include]
18 |
19 | [libs]
20 | node_modules/react-native/Libraries/react-native/react-native-interface.js
21 | node_modules/react-native/flow
22 | flow/
23 |
24 | [options]
25 | module.system=haste
26 |
27 | experimental.strict_type_args=true
28 |
29 | munge_underscores=true
30 |
31 | 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\)$' -> 'RelativeImageStub'
32 |
33 | suppress_type=$FlowIssue
34 | suppress_type=$FlowFixMe
35 | suppress_type=$FixMe
36 |
37 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(3[0-7]\\|[1-2][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
38 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(3[0-7]\\|1[0-9]\\|[1-2][0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
39 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
40 |
41 | unsafe.enable_getters_and_setters=true
42 |
43 | [version]
44 | ^0.37.0
45 |
--------------------------------------------------------------------------------
/ios/BlogPost/AppDelegate.m:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2015-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | */
9 |
10 | #import "AppDelegate.h"
11 |
12 | #import
13 | #import
14 |
15 | @implementation AppDelegate
16 |
17 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
18 | {
19 | NSURL *jsCodeLocation;
20 |
21 | jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
22 |
23 | RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
24 | moduleName:@"BlogPost"
25 | initialProperties:nil
26 | launchOptions:launchOptions];
27 | rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
28 |
29 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
30 | UIViewController *rootViewController = [UIViewController new];
31 | rootViewController.view = rootView;
32 | self.window.rootViewController = rootViewController;
33 | [self.window makeKeyAndVisible];
34 | return YES;
35 | }
36 |
37 | @end
38 |
--------------------------------------------------------------------------------
/android/app/BUCK:
--------------------------------------------------------------------------------
1 | import re
2 |
3 | # To learn about Buck see [Docs](https://buckbuild.com/).
4 | # To run your application with Buck:
5 | # - install Buck
6 | # - `npm start` - to start the packager
7 | # - `cd android`
8 | # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"`
9 | # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck
10 | # - `buck install -r android/app` - compile, install and run application
11 | #
12 |
13 | lib_deps = []
14 | for jarfile in glob(['libs/*.jar']):
15 | name = 'jars__' + re.sub(r'^.*/([^/]+)\.jar$', r'\1', jarfile)
16 | lib_deps.append(':' + name)
17 | prebuilt_jar(
18 | name = name,
19 | binary_jar = jarfile,
20 | )
21 |
22 | for aarfile in glob(['libs/*.aar']):
23 | name = 'aars__' + re.sub(r'^.*/([^/]+)\.aar$', r'\1', aarfile)
24 | lib_deps.append(':' + name)
25 | android_prebuilt_aar(
26 | name = name,
27 | aar = aarfile,
28 | )
29 |
30 | android_library(
31 | name = 'all-libs',
32 | exported_deps = lib_deps
33 | )
34 |
35 | android_library(
36 | name = 'app-code',
37 | srcs = glob([
38 | 'src/main/java/**/*.java',
39 | ]),
40 | deps = [
41 | ':all-libs',
42 | ':build_config',
43 | ':res',
44 | ],
45 | )
46 |
47 | android_build_config(
48 | name = 'build_config',
49 | package = 'com.blogpost',
50 | )
51 |
52 | android_resource(
53 | name = 'res',
54 | res = 'src/main/res',
55 | package = 'com.blogpost',
56 | )
57 |
58 | android_binary(
59 | name = 'app',
60 | package_type = 'debug',
61 | manifest = 'src/main/AndroidManifest.xml',
62 | keystore = '//android/keystores:debug',
63 | deps = [
64 | ':app-code',
65 | ],
66 | )
67 |
--------------------------------------------------------------------------------
/ios/BlogPost/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleDisplayName
8 | react-native-scaling-example
9 | CFBundleExecutable
10 | $(EXECUTABLE_NAME)
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | $(PRODUCT_NAME)
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | 1.0
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | 1
25 | LSRequiresIPhoneOS
26 |
27 | NSAppTransportSecurity
28 |
29 | 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 |
--------------------------------------------------------------------------------
/pages/Example.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { View, Text, Dimensions, StyleSheet, TouchableOpacity } from 'react-native';
3 | import { loremIpsum } from './contants';
4 | const { width, height } = Dimensions.get('window');
5 |
6 | const Example = () =>
7 |
8 |
9 | Awesome Blog Post Page
10 | {loremIpsum}
11 |
12 |
13 | Accept
14 |
15 |
16 | Decline
17 |
18 |
19 |
20 | ;
21 |
22 | export default Example;
23 |
24 | const styles = StyleSheet.create({
25 | container: {
26 | width: width,
27 | height: height,
28 | backgroundColor: '#E0E0E0',
29 | alignItems: 'center',
30 | justifyContent: 'center',
31 | },
32 | box: {
33 | width: 300,
34 | height: 450,
35 | backgroundColor: 'white',
36 | borderRadius: 10,
37 | padding: 10,
38 | shadowColor: 'black',
39 | shadowOpacity: 0.5,
40 | shadowRadius: 3,
41 | shadowOffset: {
42 | height: 0,
43 | width: 0
44 | },
45 | elevation: 2
46 | },
47 | title: {
48 | fontSize: 20,
49 | fontWeight: 'bold',
50 | marginBottom: 10,
51 | color: 'black'
52 | },
53 | text: {
54 | fontSize: 14,
55 | color: 'black'
56 | },
57 | buttonsContainer: {
58 | flex: 1,
59 | justifyContent: 'flex-end',
60 | alignItems: 'center'
61 | },
62 | button: {
63 | width: 150,
64 | height: 45,
65 | borderRadius: 100,
66 | marginBottom: 10,
67 | backgroundColor: '#41B6E6',
68 | alignItems: 'center',
69 | justifyContent: 'center',
70 | },
71 | buttonText: {
72 | fontWeight: 'bold',
73 | fontSize: 14,
74 | color: 'white'
75 | }
76 | });
77 |
--------------------------------------------------------------------------------
/pages/ViewPortExample.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { View, Text, Dimensions, StyleSheet, TouchableOpacity } from 'react-native';
3 | import { loremIpsum } from './contants';
4 | const { width, height } = Dimensions.get('window');
5 |
6 | const ViewPortExample = () =>
7 |
8 |
9 | Awesome Blog Post Page
10 | {loremIpsum}
11 |
12 |
13 | Accept
14 |
15 |
16 | Decline
17 |
18 |
19 |
20 | ;
21 |
22 | export default ViewPortExample;
23 |
24 | import {vw, vh} from 'react-native-viewport-units';
25 |
26 | const styles = StyleSheet.create({
27 | container: {
28 | width: width,
29 | height: height,
30 | backgroundColor: '#E0E0E0',
31 | alignItems: 'center',
32 | justifyContent: 'center',
33 | },
34 | box: {
35 | width: 80 * vw,
36 | height: 67 * vh,
37 | padding: 2.6 * vw,
38 | backgroundColor: 'white',
39 | borderRadius: 10,
40 | shadowColor: 'black',
41 | shadowOpacity: 0.5,
42 | shadowRadius: 3,
43 | shadowOffset: {
44 | height: 0,
45 | width: 0
46 | },
47 | elevation: 2
48 | },
49 | title: {
50 | fontSize: 5.3 * vw,
51 | fontWeight: 'bold',
52 | marginBottom: 2.6 * vw,
53 | color: 'black'
54 | },
55 | text: {
56 | fontSize: 3.6 * vw,
57 | color: 'black'
58 | },
59 | buttonsContainer: {
60 | flex: 1,
61 | justifyContent: 'flex-end',
62 | alignItems: 'center'
63 | },
64 | button: {
65 | width: 40 * vw,
66 | height: 10.7 * vw,
67 | borderRadius: 27 * vw,
68 | marginBottom: 2.6 * vw,
69 | backgroundColor: '#41B6E6',
70 | alignItems: 'center',
71 | justifyContent: 'center',
72 | },
73 | buttonText: {
74 | fontWeight: 'bold',
75 | fontSize: 3.6 * vw,
76 | color: 'white'
77 | }
78 | });
79 |
--------------------------------------------------------------------------------
/pages/FlexExample.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { View, Text, Dimensions, StyleSheet, TouchableOpacity } from 'react-native';
3 | import { loremIpsum } from './contants';
4 | const { width, height } = Dimensions.get('window');
5 |
6 | const FlexExample = () =>
7 |
8 |
9 |
10 |
11 |
12 | Awesome Blog Post Page
13 | {loremIpsum}
14 |
15 |
16 | Accept
17 |
18 |
19 | Decline
20 |
21 |
22 |
23 |
24 |
25 |
26 | ;
27 |
28 | export default FlexExample;
29 |
30 | const styles = StyleSheet.create({
31 | container: {
32 | backgroundColor: '#E0E0E0',
33 | alignItems: 'center',
34 | justifyContent: 'center',
35 | },
36 | box: {
37 | backgroundColor: 'white',
38 | borderRadius: 10,
39 | padding: 10,
40 | shadowColor: 'black',
41 | shadowOpacity: 0.5,
42 | shadowRadius: 3,
43 | shadowOffset: {
44 | height: 0,
45 | width: 0
46 | },
47 | elevation: 2
48 | },
49 | title: {
50 | fontSize: 20,
51 | fontWeight: 'bold',
52 | marginBottom: 10,
53 | color: 'black'
54 | },
55 | text: {
56 | fontSize: 14,
57 | color: 'black'
58 | },
59 | buttonsContainer: {
60 | flex: 1,
61 | justifyContent: 'flex-end',
62 | alignItems: 'center'
63 | },
64 | button: {
65 | width: 150,
66 | height: 45,
67 | borderRadius: 100,
68 | marginBottom: 10,
69 | backgroundColor: '#41B6E6',
70 | alignItems: 'center',
71 | justifyContent: 'center',
72 | },
73 | buttonText: {
74 | fontWeight: 'bold',
75 | fontSize: 14,
76 | color: 'white'
77 | }
78 | });
79 |
--------------------------------------------------------------------------------
/pages/ScalingExample.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { View, Text, Dimensions, StyleSheet, TouchableOpacity } from 'react-native';
3 | import { loremIpsum } from './contants';
4 | const { width, height } = Dimensions.get('window');
5 |
6 | const ScalingExample = () =>
7 |
8 |
9 | Awesome Blog Post Page
10 | {loremIpsum}
11 |
12 |
13 | Accept
14 |
15 |
16 | Decline
17 |
18 |
19 |
20 | ;
21 |
22 | export default ScalingExample;
23 |
24 | import { scale, moderateScale, verticalScale} from './scaling';
25 |
26 | const styles = StyleSheet.create({
27 | container: {
28 | width: width,
29 | height: height,
30 | backgroundColor: '#E0E0E0',
31 | alignItems: 'center',
32 | justifyContent: 'center',
33 | },
34 | box: {
35 | width: moderateScale(300),
36 | height: verticalScale(450),
37 | padding: scale(10),
38 | backgroundColor: 'white',
39 | borderRadius: 10,
40 | shadowColor: 'black',
41 | shadowOpacity: 0.5,
42 | shadowRadius: 3,
43 | shadowOffset: {
44 | height: 0,
45 | width: 0
46 | },
47 | elevation: 2
48 | },
49 | title: {
50 | fontSize: moderateScale(20, 0.4),
51 | fontWeight: 'bold',
52 | marginBottom: scale(10),
53 | color: 'black'
54 | },
55 | text: {
56 | fontSize: moderateScale(14),
57 | color: 'black'
58 | },
59 | buttonsContainer: {
60 | flex: 1,
61 | justifyContent: 'flex-end',
62 | alignItems: 'center'
63 | },
64 | button: {
65 | width: moderateScale(150, 0.3),
66 | height: moderateScale(45, 0.3),
67 | borderRadius: 100,
68 | marginBottom: moderateScale(10, 0.6),
69 | backgroundColor: '#41B6E6',
70 | alignItems: 'center',
71 | justifyContent: 'center',
72 | },
73 | buttonText: {
74 | fontWeight: 'bold',
75 | fontSize: moderateScale(14),
76 | color: 'white'
77 | }
78 | });
79 |
--------------------------------------------------------------------------------
/android/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Disabling obfuscation is useful if you collect stack traces from production crashes
20 | # (unless you are using a system that supports de-obfuscate the stack traces).
21 | -dontobfuscate
22 |
23 | # React Native
24 |
25 | # Keep our interfaces so they can be used by other ProGuard rules.
26 | # See http://sourceforge.net/p/proguard/bugs/466/
27 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip
28 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters
29 | -keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip
30 |
31 | # Do not strip any method/class that is annotated with @DoNotStrip
32 | -keep @com.facebook.proguard.annotations.DoNotStrip class *
33 | -keep @com.facebook.common.internal.DoNotStrip class *
34 | -keepclassmembers class * {
35 | @com.facebook.proguard.annotations.DoNotStrip *;
36 | @com.facebook.common.internal.DoNotStrip *;
37 | }
38 |
39 | -keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * {
40 | void set*(***);
41 | *** get*();
42 | }
43 |
44 | -keep class * extends com.facebook.react.bridge.JavaScriptModule { *; }
45 | -keep class * extends com.facebook.react.bridge.NativeModule { *; }
46 | -keepclassmembers,includedescriptorclasses class * { native ; }
47 | -keepclassmembers class * { @com.facebook.react.uimanager.UIProp ; }
48 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp ; }
49 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup ; }
50 |
51 | -dontwarn com.facebook.react.**
52 |
53 | # okhttp
54 |
55 | -keepattributes Signature
56 | -keepattributes *Annotation*
57 | -keep class okhttp3.** { *; }
58 | -keep interface okhttp3.** { *; }
59 | -dontwarn okhttp3.**
60 |
61 | # okio
62 |
63 | -keep class sun.misc.Unsafe { *; }
64 | -dontwarn java.nio.file.*
65 | -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
66 | -dontwarn okio.**
67 |
--------------------------------------------------------------------------------
/android/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/ios/BlogPost/Base.lproj/LaunchScreen.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
21 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/ios/BlogPost.xcodeproj/xcshareddata/xcschemes/BlogPost.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
29 |
35 |
36 |
37 |
43 |
49 |
50 |
51 |
52 |
53 |
58 |
59 |
60 |
61 |
67 |
68 |
69 |
70 |
71 |
72 |
82 |
84 |
90 |
91 |
92 |
93 |
94 |
95 |
101 |
103 |
109 |
110 |
111 |
112 |
114 |
115 |
118 |
119 |
120 |
--------------------------------------------------------------------------------
/ios/BlogPost.xcodeproj/xcshareddata/xcschemes/BlogPost-tvOS.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
29 |
35 |
36 |
37 |
43 |
49 |
50 |
51 |
52 |
53 |
58 |
59 |
61 |
67 |
68 |
69 |
70 |
71 |
77 |
78 |
79 |
80 |
81 |
82 |
92 |
94 |
100 |
101 |
102 |
103 |
104 |
105 |
111 |
113 |
119 |
120 |
121 |
122 |
124 |
125 |
128 |
129 |
130 |
--------------------------------------------------------------------------------
/android/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/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
19 | * entryFile: "index.android.js",
20 | *
21 | * // whether to bundle JS and assets in debug mode
22 | * bundleInDebug: false,
23 | *
24 | * // whether to bundle JS and assets in release mode
25 | * bundleInRelease: true,
26 | *
27 | * // whether to bundle JS and assets in another build variant (if configured).
28 | * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
29 | * // The configuration property can be in the following formats
30 | * // 'bundleIn${productFlavor}${buildType}'
31 | * // 'bundleIn${buildType}'
32 | * // bundleInFreeDebug: true,
33 | * // bundleInPaidRelease: true,
34 | * // bundleInBeta: true,
35 | *
36 | * // the root of your project, i.e. where "package.json" lives
37 | * root: "../../",
38 | *
39 | * // where to put the JS bundle asset in debug mode
40 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
41 | *
42 | * // where to put the JS bundle asset in release mode
43 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release",
44 | *
45 | * // where to put drawable resources / React Native assets, e.g. the ones you use via
46 | * // require('./image.png')), in debug mode
47 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
48 | *
49 | * // where to put drawable resources / React Native assets, e.g. the ones you use via
50 | * // require('./image.png')), in release mode
51 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
52 | *
53 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means
54 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
55 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle
56 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
57 | * // for example, you might want to remove it from here.
58 | * inputExcludes: ["android/**", "ios/**"],
59 | *
60 | * // override which node gets called and with what additional arguments
61 | * nodeExecutableAndArgs: ["node"]
62 | *
63 | * // supply additional arguments to the packager
64 | * extraPackagerArgs: []
65 | * ]
66 | */
67 |
68 | apply from: "../../node_modules/react-native/react.gradle"
69 |
70 | /**
71 | * Set this to true to create two separate APKs instead of one:
72 | * - An APK that only works on ARM devices
73 | * - An APK that only works on x86 devices
74 | * The advantage is the size of the APK is reduced by about 4MB.
75 | * Upload all the APKs to the Play Store and people will download
76 | * the correct one based on the CPU architecture of their device.
77 | */
78 | def enableSeparateBuildPerCPUArchitecture = false
79 |
80 | /**
81 | * Run Proguard to shrink the Java bytecode in release builds.
82 | */
83 | def enableProguardInReleaseBuilds = false
84 |
85 | android {
86 | compileSdkVersion 23
87 | buildToolsVersion "23.0.1"
88 |
89 | defaultConfig {
90 | applicationId "com.blogpost"
91 | minSdkVersion 16
92 | targetSdkVersion 22
93 | versionCode 1
94 | versionName "1.0"
95 | ndk {
96 | abiFilters "armeabi-v7a", "x86"
97 | }
98 | }
99 | splits {
100 | abi {
101 | reset()
102 | enable enableSeparateBuildPerCPUArchitecture
103 | universalApk false // If true, also generate a universal APK
104 | include "armeabi-v7a", "x86"
105 | }
106 | }
107 | buildTypes {
108 | release {
109 | minifyEnabled enableProguardInReleaseBuilds
110 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
111 | }
112 | }
113 | // applicationVariants are e.g. debug, release
114 | applicationVariants.all { variant ->
115 | variant.outputs.each { output ->
116 | // For each separate APK per architecture, set a unique version code as described here:
117 | // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
118 | def versionCodes = ["armeabi-v7a":1, "x86":2]
119 | def abi = output.getFilter(OutputFile.ABI)
120 | if (abi != null) { // null for the universal-debug, universal-release variants
121 | output.versionCodeOverride =
122 | versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
123 | }
124 | }
125 | }
126 | }
127 |
128 | dependencies {
129 | compile fileTree(dir: "libs", include: ["*.jar"])
130 | compile "com.android.support:appcompat-v7:23.0.1"
131 | compile "com.facebook.react:react-native:+" // From node_modules
132 | }
133 |
134 | // Run this once to be able to run the application with BUCK
135 | // puts all compile dependencies into folder libs for BUCK to use
136 | task copyDownloadableDepsToLibs(type: Copy) {
137 | from configurations.compile
138 | into 'libs'
139 | }
140 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
Size matters: how I used React Native to make my app look great on every device
2 |
3 |
4 | *Every example on this post can be found [here](https://github.com/Nirsky/react-native-scaling-example).*
5 |
6 | Have you ever had your designer hand you a cool design for your React Native app that you developed on, say, an iPhone 7 - and when you try to run it on a tablet,
7 | it looks like it was left in the dryer for too long?
8 |
9 | That's probably because the design was created using pixels whereas all dimensions in React Native are unitless,
10 | represented by “dp” (density-independent pixels). Simply put - the bigger your device is, the more dp it'll have.
11 |
12 | When working with React Native, the iPhone 7 has **375dp** width and **667dp** height and a Galaxy Tab A 8.0" Tablet (the one I'm using) has **768dp** width and **1024dp** height.
13 |
14 | So while a `` will cover most of your iPhone's screen,
15 | it will cover less than half of your tablet's screen.
16 |
17 |
So how can I make my app beautiful on the tablet as well?
18 | Glad you asked. On this blog post I'll show several methods for scaling your components to different screen sizes, and which one I found to work best.
19 |
20 | To do this, I created a small example app, and after every scaling method I'll attach the code along with screenshots for both a tablet and an iPhone.
21 |
22 |
114 |
115 | That's definitely not how we want our component to look like on a tablet (did I say dryer already?).
116 |
117 |
Method 1: Flex
118 |
119 | If you're not familiar with flex I urge you to read about it online.
120 | For starters check this [flex playground](https://codepen.io/enxaneta/full/adLPwv)
121 | or read about it on the [RN Docs](https://facebook.github.io/react-native/docs/flexbox.html).
122 |
123 | When developing a scalable component with flex you need to convert your View's size **and its margins** with
124 | proportion to the parent component. If for example your container's width is 375 and your box's width is 300 -
125 | the box's width is 80% of the parent (300/375) and the margins are what left - 10% on the left and 10% on the right.
126 |
127 | Alternatively, you can keep your margins static (represented by dp) and spread it across the available space using `flex: 1`.
128 |
129 | Here's an example of how I *flexed* my component. I only flexed the white box and skipped flexing the buttons because I'm lazy,
130 | but you get the point (StyleSheet stayed the same except `width` and `height` were removed from `box` and `container`):
131 |
132 | ```javascript
133 | const FlexExample = () =>
134 |
135 |
136 |
137 |
138 |
139 | Awesome Blog Post Page
140 | {loremIpsum}
141 |
142 |
143 | Accept
144 |
145 |
146 | Decline
147 |
148 |
149 |
150 |
151 |
152 |
153 | ;
154 | ```
155 |
156 | And the result:
157 |
158 |
159 |
160 |
161 |
162 |
163 | Flex is your best friend when creating a scalable **layout**, especially when wanting to spread it across the entire width or height (i.e. a list item)
164 | or when dividing a component to different sections. It will keep the same proportions among different devices, even when changing orientation.
165 |
166 | While flex is an amazing tool for scaling, it's not always enough.
167 | With flex, some components won't scale easily and it’s limited to certain properties like width, height, margin and padding.
168 | Stuff like fontSize, lineHeight or SVG size can't be flexed.
169 |
170 | With that said, let’s continue to our second method.
171 |
172 |
173 |
174 |
Method 2: Viewport Units
175 | With this method you basically convert every number you'd like to scale in your StyleSheet to
176 | a percentage of the device's width or height.
177 | If your device's width is 375dp then 300dp will become `deviceWidth * 0.8` (since 300/375 = 0.8),
178 | and you can also do it with smaller numbers, for example `fontSize: 14` will become `fontSize: deviceWidth * 0.037`.
179 | A nice and straight-forward library that can simplify this method is [react-native-viewport-units](https://github.com/jmstout/react-native-viewport-units).
180 |
181 | This is the StyleSheet after *viewporting* stuff around (Irrelevant parts were removed, component is exactly the same as the first example):
182 |
183 | ```javascript
184 | import {vw, vh} from 'react-native-viewport-units';
185 |
186 | const styles = StyleSheet.create({
187 | container: {
188 | ...
189 | },
190 | box: {
191 | width: 80 * vw,
192 | height: 67 * vh,
193 | padding: 2.6 * vw,
194 | ...
195 | },
196 | title: {
197 | fontSize: 5.3 * vw,
198 | marginBottom: 2.6 * vw,
199 | fontWeight: 'bold',
200 | color: 'black'
201 | },
202 | text: {
203 | fontSize: 3.6 * vw,
204 | color: 'black'
205 | },
206 | buttonsContainer: {
207 | ...
208 | },
209 | button: {
210 | width: 40 * vw,
211 | height: 10.7 * vw,
212 | borderRadius: 27 * vw,
213 | marginBottom: 2.6 * vw,
214 | ...
215 | },
216 | buttonText: {
217 | fontWeight: 'bold',
218 | fontSize: 3.6 * vw,
219 | color: 'white'
220 | }
221 | });
222 | ```
223 |
224 | And of course, what you have all been waiting for... the result:
225 |
226 |
227 |
228 |
229 |
230 |
231 | _Note: You'll be able to achieve more or less the same result using the
232 | new [percentage support](https://github.com/facebook/react-native/commit/3f49e743bea730907066677c7cbfbb1260677d11) (RN 0.43 and up)
233 | or by multiplying everything with `PixelRatio.get()`._
234 |
235 | Besides needing to do some calculation and having weird numbers around, pretty neat and easy, right?
236 | ...but still not perfect. What if you show your designer how it looks on the tablet and he thinks the buttons are too big and the box's width should be reduced.
237 | What can you do? If you reduce the viewports it will affect the iPhone as well.
238 |
239 | One option is to do something like HTML's `media-query` using [PixelRatio](https://facebook.github.io/react-native/docs/pixelratio.html).
240 | But as I said, I'm lazy and I don't want to write everything 2 or more times, what can I do?
241 |
242 |
243 |
Method 3: Scaling Utils
244 | Here at Soluto, we wrote these 3 simple functions that make our scaling so much easier:
245 |
246 | ```javascript
247 | import { Dimensions } from 'react-native';
248 | const { width, height } = Dimensions.get('window');
249 |
250 | //Guideline sizes are based on standard ~5" screen mobile device
251 | const guidelineBaseWidth = 350;
252 | const guidelineBaseHeight = 680;
253 |
254 | const scale = size => width / guidelineBaseWidth * size;
255 | const verticalScale = size => height / guidelineBaseHeight * size;
256 | const moderateScale = (size, factor = 0.5) => size + ( scale(size) - size ) * factor;
257 |
258 | export {scale, verticalScale, moderateScale};
259 | ```
260 | The purpose of these functions is to be able to take one design (from a standard mobile phone) and apply it to other display sizes.
261 | `scale` function is pretty straight forward and will return the same linear result as using viewport.
262 | `verticalScale` is like scale, but based on height instead of width, which can be useful.
263 | The real magic happens at `moderateScale`. The cool thing about it is that you can control the resize factor (default is 0.5).
264 | So if normal scale will increase your size by +2X, moderateScale will only increase it by +X.
265 | Or if the resize factor is 0.25, instead of increasing by +2X it will increase by +0.5X.
266 |
267 | If you want to scale a View with 300dp width, on the iPhone 7 you will get:
268 | - scale(300) = 320
269 | - moderateScale(300) = 310
270 | - moderateScale(300, 0.25) = 305
271 |
272 | On the Galaxy Tab Tablet:
273 | - scale(300) = 300 + 360 = 660
274 | - moderateScale(300) = 300 + 360/2 = 480
275 | - moderateScale(300, 0.25) = 300 + 360/4 = 390
276 |
277 | This allow us to write only once, keeping stuff roughly the same size across mobile phones without looking massive and bulky on tablets.
278 | Anyways, enough talking. Here are the results after applying scaling utils on the original dp sizes until your designer is pleased.
279 |
280 | StyleSheet:
281 | ```javascript
282 | import { scale, moderateScale, verticalScale} from './scaling';
283 |
284 | const styles = StyleSheet.create({
285 | ...
286 | box: {
287 | width: moderateScale(300),
288 | height: verticalScale(450),
289 | padding: scale(10),
290 | ...
291 | },
292 | title: {
293 | fontSize: moderateScale(20, 0.4),
294 | marginBottom: scale(10),
295 | ...
296 | },
297 | text: {
298 | fontSize: moderateScale(14),
299 | ...
300 | },
301 | button: {
302 | width: moderateScale(150, 0.3),
303 | height: moderateScale(45, 0.3),
304 | marginBottom: moderateScale(10),
305 | ...
306 | },
307 | buttonText: {
308 | fontSize: moderateScale(14),
309 | ...
310 | }
311 | });
312 | ```
313 |
314 | Result:
315 |