瀏覽代碼

showModal android

Daniel Zlotin 7 年之前
父節點
當前提交
ec0493fb01

+ 3
- 3
AndroidE2E/app/build.gradle 查看文件

@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
2 2
 
3 3
 android {
4 4
     compileSdkVersion 25
5
-    buildToolsVersion "25.0.2"
5
+    buildToolsVersion "25.0.3"
6 6
     defaultConfig {
7 7
         applicationId "com.reactnativenavigation.e2e.androide2e"
8 8
         minSdkVersion 18
@@ -16,10 +16,10 @@ android {
16 16
 
17 17
 dependencies {
18 18
     compile fileTree(dir: 'libs', include: ['*.jar'])
19
-    compile 'com.android.support:appcompat-v7:25.1.1'
19
+    compile 'com.android.support:appcompat-v7:25.3.1'
20 20
 
21 21
     androidTestCompile 'org.assertj:assertj-core:2.5.0'
22
-    androidTestCompile 'com.android.support:support-annotations:25.1.1'
22
+    androidTestCompile 'com.android.support:support-annotations:25.3.1'
23 23
     androidTestCompile 'com.android.support.test:runner:0.5'
24 24
     androidTestCompile 'com.android.support.test:rules:0.5'
25 25
     androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'

+ 1
- 1
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/ModalsTest.java 查看文件

@@ -6,7 +6,7 @@ import org.junit.Ignore;
6 6
 import org.junit.Test;
7 7
 
8 8
 public class ModalsTest extends BaseTest {
9
-	@Ignore
9
+
10 10
 	@Test
11 11
 	public void showModal() throws Exception {
12 12
 		launchTheApp();

+ 1
- 1
AndroidE2E/build.gradle 查看文件

@@ -5,7 +5,7 @@ buildscript {
5 5
         jcenter()
6 6
     }
7 7
     dependencies {
8
-        classpath 'com.android.tools.build:gradle:2.3.0'
8
+        classpath 'com.android.tools.build:gradle:2.3.2'
9 9
 
10 10
         // NOTE: Do not place your application dependencies here; they belong
11 11
         // in the individual module build.gradle files

+ 12
- 0
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java 查看文件

@@ -84,6 +84,18 @@ public class NavigationModule extends ReactContextBaseJavaModule {
84 84
 		});
85 85
 	}
86 86
 
87
+	@ReactMethod
88
+	public void showModal(final ReadableMap rawLayoutTree) {
89
+		final LayoutNode layoutTree = LayoutNodeParser.parse(JSONParser.parse(rawLayoutTree));
90
+		handle(new Runnable() {
91
+			@Override
92
+			public void run() {
93
+				final ViewController viewController = newLayoutFactory().create(layoutTree);
94
+				navigator().showModal(viewController);
95
+			}
96
+		});
97
+	}
98
+
87 99
 	private NavigationActivity activity() {
88 100
 		return (NavigationActivity) getCurrentActivity();
89 101
 	}

+ 12
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/Navigator.java 查看文件

@@ -1,15 +1,20 @@
1 1
 package com.reactnativenavigation.viewcontrollers;
2 2
 
3 3
 import android.app.Activity;
4
+import android.app.Dialog;
4 5
 import android.support.annotation.NonNull;
5 6
 import android.view.ViewGroup;
6 7
 import android.widget.FrameLayout;
7 8
 
9
+import com.reactnativenavigation.R;
8 10
 import com.reactnativenavigation.utils.CompatUtils;
9 11
 
10 12
 import java.util.Collection;
11 13
 import java.util.Collections;
12 14
 
15
+import static android.view.View.MeasureSpec.EXACTLY;
16
+import static android.view.View.MeasureSpec.makeMeasureSpec;
17
+
13 18
 public class Navigator extends ParentController {
14 19
 
15 20
 	private ViewController root;
@@ -96,4 +101,11 @@ public class Navigator extends ParentController {
96 101
 			}
97 102
 		}
98 103
 	}
104
+
105
+	public void showModal(final ViewController viewController) {
106
+		viewController.getView().measure(makeMeasureSpec(getView().getWidth(), EXACTLY), makeMeasureSpec(getView().getHeight(), EXACTLY));
107
+		Dialog dialog = new Dialog(getActivity(), R.style.Modal);
108
+		dialog.setContentView(viewController.getView());
109
+		dialog.show();
110
+	}
99 111
 }

+ 8
- 5
lib/android/app/src/main/res/anim/slide_up.xml 查看文件

@@ -1,9 +1,12 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2 2
 <set xmlns:android="http://schemas.android.com/apk/res/android"
3
-    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
4
-    android:shareInterpolator="true">
3
+     android:duration="250"
4
+     android:interpolator="@android:anim/decelerate_interpolator"
5
+     android:shareInterpolator="true">
5 6
     <translate
6
-        android:fromYDelta="100%"
7
-        android:toYDelta="0"
8
-        android:duration="250"/>
7
+        android:fromYDelta="60%"
8
+        android:toYDelta="0"/>
9
+    <alpha
10
+        android:fromAlpha="0"
11
+        android:toAlpha="1"/>
9 12
 </set>

+ 2
- 1
lib/android/app/src/main/res/values/styles.xml 查看文件

@@ -1,11 +1,12 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2 2
 <resources>
3 3
 
4
-    <style name="Modal" parent="@android:style/Theme.Translucent.NoTitleBar">
4
+    <style name="Modal" parent="Theme.AppCompat.Light.NoActionBar">
5 5
         <item name="android:windowAnimationStyle">@style/modalAnimations</item>
6 6
     </style>
7 7
 
8 8
     <style name="modalAnimations">
9
+        <item name="android:windowEnterAnimation">@anim/slide_up</item>
9 10
         <item name="android:windowExitAnimation">@anim/slide_down</item>
10 11
     </style>
11 12
 </resources>

+ 2
- 2
playground/android/app/build.gradle 查看文件

@@ -36,7 +36,7 @@ android {
36 36
 dependencies {
37 37
     compile fileTree(dir: 'libs', include: ['*.jar'])
38 38
     compile 'com.facebook.react:react-native:+'
39
-    compile 'com.android.support:design:25.1.1'
40
-    compile "com.android.support:appcompat-v7:25.1.1"
39
+    compile 'com.android.support:design:25.3.1'
40
+    compile "com.android.support:appcompat-v7:25.3.1"
41 41
     compile project(':react-native-navigation')
42 42
 }

+ 1
- 1
playground/android/build.gradle 查看文件

@@ -5,7 +5,7 @@ buildscript {
5 5
         jcenter()
6 6
     }
7 7
     dependencies {
8
-        classpath 'com.android.tools.build:gradle:2.3.0'
8
+        classpath 'com.android.tools.build:gradle:2.3.2'
9 9
 
10 10
         // NOTE: Do not place your application dependencies here; they belong
11 11
         // in the individual module build.gradle files

+ 0
- 10
scripts/env/installAndroidSDK.sh 查看文件

@@ -17,13 +17,3 @@ curl --location https://dl.google.com/android/repository/sdk-tools-darwin-385939
17 17
 echo "Copying Android Licenses"
18 18
 mkdir -p "${ANDROID_HOME}"/licenses
19 19
 cp "$scriptdir/android-sdk-licenses/"* "${ANDROID_HOME}"/licenses
20
-
21
-# package="system-images;android-24;default;armeabi-v7a"
22
-# echo "Downloading emulator"
23
-# sdkmanager "emulator"
24
-# echo "Downloading $package"
25
-# sdkmanager "${package}"
26
-# echo "Creating avd"
27
-# echo no | avdmanager create avd --force --name "pixel" --abi "default/armeabi-v7a" --package "${package}" --device "pixel"
28
-# sleep 2
29
-# avdmanager list avd

+ 14
- 7
scripts/test.e2e.android.js 查看文件

@@ -2,6 +2,12 @@
2 2
 const _ = require('lodash');
3 3
 const exec = require('shell-utils').exec;
4 4
 
5
+const avdName = 'pixel';
6
+const sdk = 'android-24';
7
+const apis = 'default';
8
+const abi = 'armeabi-v7a';
9
+const packageName = `system-images;${sdk};${apis};${abi}`;
10
+
5 11
 const release = _.includes(process.argv, 'release');
6 12
 
7 13
 run();
@@ -9,12 +15,6 @@ run();
9 15
 function run() {
10 16
   if (process.env.CI) {
11 17
     console.log(`android e2e is disabled on CI`);
12
-    // try {
13
-    //   launchEmulator();
14
-    //   runTests();
15
-    // } finally {
16
-    //   killEmulators();
17
-    // }
18 18
   } else {
19 19
     runTests();
20 20
   }
@@ -26,9 +26,16 @@ function runTests() {
26 26
   exec.execSync(`cd AndroidE2E && ./gradlew connectedDebugAndroidTest`);
27 27
 }
28 28
 
29
+function installEmulator() {
30
+  exec.execSync(`sdkmanager "emulator"`);
31
+  exec.execSync(`sdkmanager "${packageName}"`);
32
+  exec.execSync(`echo no | avdmanager create avd --force --name "${avdName}" --abi "${apis}/${abi}" --package "${packageName}" --device "pixel"`);
33
+  exec.execSync(`avdmanager list avd`);
34
+}
35
+
29 36
 function launchEmulator() {
30 37
   console.log(`Launching Android Emulator`);
31
-  exec.execSync(`cd $ANDROID_HOME/tools && ./emulator -skin 1080x1920 -gpu host -no-audio @pixel`);
38
+  exec.execSync(`cd $ANDROID_HOME/tools && ./emulator -skin 1080x1920 -gpu host -no-audio @${avdName}`);
32 39
   exec.execSync(`./scripts/waitForAndroidEmulator.sh`);
33 40
 }
34 41