Browse Source

Orientation.hasValue returns false for default orientation

This bug caused orientation set in defaultOptions to be disregarded.

Setting default orientation is still somewhat wrong now that its behaviour has changed when targeting SDK 28.
Guy Carmeli 5 years ago
parent
commit
43ae659097

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/parse/OrientationOptions.java View File

@@ -53,7 +53,7 @@ public class OrientationOptions {
53 53
     }
54 54
 
55 55
     public boolean hasValue() {
56
-        return !orientations.isEmpty();
56
+        return !orientations.isEmpty() && !(orientations.size() == 1 && orientations.get(0) == Orientation.Default);
57 57
     }
58 58
 
59 59
     @CheckResult

+ 13
- 7
lib/android/app/src/test/java/com/reactnativenavigation/parse/OrientationOptionsTest.java View File

@@ -20,13 +20,13 @@ public class OrientationOptionsTest extends BaseTest {
20 20
     }
21 21
 
22 22
     @Test
23
-    public void parse() throws Exception {
23
+    public void parse() {
24 24
         OrientationOptions options = OrientationOptions.parse(create("default"));
25 25
         assertThat(options.orientations).hasSize(1);
26 26
     }
27 27
 
28 28
     @Test
29
-    public void parseOrientations() throws Exception {
29
+    public void parseOrientations() {
30 30
         OrientationOptions options = OrientationOptions.parse(create("default", "landscape", "portrait"));
31 31
         assertThat(options.orientations.get(0)).isEqualTo(Orientation.Default);
32 32
         assertThat(options.orientations.get(1)).isEqualTo(Orientation.Landscape);
@@ -34,36 +34,42 @@ public class OrientationOptionsTest extends BaseTest {
34 34
     }
35 35
 
36 36
     @Test
37
-    public void parseSingleOrientation() throws Exception {
37
+    public void parseSingleOrientation() {
38 38
         OrientationOptions options = OrientationOptions.parse(create("landscape"));
39 39
         assertThat(options.orientations.get(0)).isEqualTo(Orientation.Landscape);
40 40
     }
41 41
 
42 42
     @Test
43
-    public void landscapePortrait_regardedAsUserOrientation() throws Exception {
43
+    public void landscapePortrait_regardedAsUserOrientation() {
44 44
         OrientationOptions options = OrientationOptions.parse(create("landscape", "portrait"));
45 45
         assertThat(options.getValue()).isEqualTo(Orientation.PortraitLandscape.orientationCode);
46 46
     }
47 47
 
48 48
     @Test
49
-    public void portraitLandscape_regardedAsUserOrientation() throws Exception {
49
+    public void portraitLandscape_regardedAsUserOrientation() {
50 50
         OrientationOptions options = OrientationOptions.parse(create("portrait", "landscape"));
51 51
         assertThat(options.getValue()).isEqualTo(Orientation.PortraitLandscape.orientationCode);
52 52
     }
53 53
 
54 54
     @Test
55
-    public void unsupportedOrientationsAreIgnored() throws Exception {
55
+    public void unsupportedOrientationsAreIgnored() {
56 56
         OrientationOptions options = OrientationOptions.parse(create("default", "autoRotate"));
57 57
         assertThat(options.orientations).hasSize(1);
58 58
         assertThat(options.orientations.get(0)).isEqualTo(Orientation.Default);
59 59
     }
60 60
 
61 61
     @Test
62
-    public void getValue_returnsDefaultIfUndefined() throws Exception {
62
+    public void getValue_returnsDefaultIfUndefined() {
63 63
         OrientationOptions options = new OrientationOptions();
64 64
         assertThat(options.getValue()).isEqualTo(Orientation.Default.orientationCode);
65 65
     }
66 66
 
67
+    @Test
68
+    public void hasValue_returnsFalseForOrientationDefault() {
69
+        OrientationOptions options = OrientationOptions.parse(create("default"));
70
+        assertThat(options.hasValue()).isFalse();
71
+    }
72
+
67 73
     private JSONObject create(String... orientations) {
68 74
         JSONObject orientation = new JSONObject();
69 75
         try {

+ 4
- 5
playground/android/app/build.gradle View File

@@ -8,8 +8,7 @@ project.ext.react = [
8 8
 apply from: "../../../node_modules/react-native/react.gradle"
9 9
 
10 10
 android {
11
-    compileSdkVersion 26
12
-    buildToolsVersion "27.0.3"
11
+    compileSdkVersion 28
13 12
 
14 13
     compileOptions {
15 14
         sourceCompatibility JavaVersion.VERSION_1_8
@@ -19,7 +18,7 @@ android {
19 18
     defaultConfig {
20 19
         applicationId "com.reactnativenavigation.playground"
21 20
         minSdkVersion 21
22
-        targetSdkVersion 25
21
+        targetSdkVersion 28
23 22
         versionCode 1
24 23
         versionName "1.0"
25 24
         ndk {
@@ -57,8 +56,8 @@ configurations.all {
57 56
 
58 57
 dependencies {
59 58
     implementation fileTree(dir: 'libs', include: ['*.jar'])
60
-    implementation 'com.android.support:design:26.1.0'
61
-    implementation 'com.android.support:appcompat-v7:26.1.0'
59
+    implementation 'com.android.support:design:28.0.0'
60
+    implementation 'com.android.support:appcompat-v7:28.0.0'
62 61
 
63 62
     //noinspection GradleDynamicVersion
64 63
     implementation 'com.facebook.react:react-native:+'

+ 2
- 1
playground/src/app.js View File

@@ -25,7 +25,8 @@ function start() {
25 25
   Navigation.events().registerAppLaunchedListener(async () => {
26 26
     Navigation.setDefaultOptions({
27 27
       layout: {
28
-        componentBackgroundColor: '#e8e8e8'
28
+        componentBackgroundColor: '#e8e8e8',
29
+        orientation: ['portrait']
29 30
       },
30 31
       bottomTab: {
31 32
         iconColor: '#1B4C77',

+ 3
- 0
playground/src/screens/WelcomeScreen.js View File

@@ -277,6 +277,9 @@ class WelcomeScreen extends Component {
277 277
       component: {
278 278
         name: 'navigation.playground.PushedScreen',
279 279
         options: {
280
+          layout: {
281
+            
282
+          },
280 283
           topBar: {
281 284
             title: {
282 285
               text: 'pushed',