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 6 years ago
parent
commit
43ae659097

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

53
     }
53
     }
54
 
54
 
55
     public boolean hasValue() {
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
     @CheckResult
59
     @CheckResult

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

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

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

8
 apply from: "../../../node_modules/react-native/react.gradle"
8
 apply from: "../../../node_modules/react-native/react.gradle"
9
 
9
 
10
 android {
10
 android {
11
-    compileSdkVersion 26
12
-    buildToolsVersion "27.0.3"
11
+    compileSdkVersion 28
13
 
12
 
14
     compileOptions {
13
     compileOptions {
15
         sourceCompatibility JavaVersion.VERSION_1_8
14
         sourceCompatibility JavaVersion.VERSION_1_8
19
     defaultConfig {
18
     defaultConfig {
20
         applicationId "com.reactnativenavigation.playground"
19
         applicationId "com.reactnativenavigation.playground"
21
         minSdkVersion 21
20
         minSdkVersion 21
22
-        targetSdkVersion 25
21
+        targetSdkVersion 28
23
         versionCode 1
22
         versionCode 1
24
         versionName "1.0"
23
         versionName "1.0"
25
         ndk {
24
         ndk {
57
 
56
 
58
 dependencies {
57
 dependencies {
59
     implementation fileTree(dir: 'libs', include: ['*.jar'])
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
     //noinspection GradleDynamicVersion
62
     //noinspection GradleDynamicVersion
64
     implementation 'com.facebook.react:react-native:+'
63
     implementation 'com.facebook.react:react-native:+'

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

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

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

277
       component: {
277
       component: {
278
         name: 'navigation.playground.PushedScreen',
278
         name: 'navigation.playground.PushedScreen',
279
         options: {
279
         options: {
280
+          layout: {
281
+            
282
+          },
280
           topBar: {
283
           topBar: {
281
             title: {
284
             title: {
282
               text: 'pushed',
285
               text: 'pushed',