Skip to content

Commit

Permalink
Orientation.hasValue returns false for default orientation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
guyca committed Dec 24, 2018
1 parent ee04610 commit 43ae659
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public int getValue() {
}

public boolean hasValue() {
return !orientations.isEmpty();
return !orientations.isEmpty() && !(orientations.size() == 1 && orientations.get(0) == Orientation.Default);
}

@CheckResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,50 +20,56 @@ public void beforeEach() {
}

@Test
public void parse() throws Exception {
public void parse() {
OrientationOptions options = OrientationOptions.parse(create("default"));
assertThat(options.orientations).hasSize(1);
}

@Test
public void parseOrientations() throws Exception {
public void parseOrientations() {
OrientationOptions options = OrientationOptions.parse(create("default", "landscape", "portrait"));
assertThat(options.orientations.get(0)).isEqualTo(Orientation.Default);
assertThat(options.orientations.get(1)).isEqualTo(Orientation.Landscape);
assertThat(options.orientations.get(2)).isEqualTo(Orientation.Portrait);
}

@Test
public void parseSingleOrientation() throws Exception {
public void parseSingleOrientation() {
OrientationOptions options = OrientationOptions.parse(create("landscape"));
assertThat(options.orientations.get(0)).isEqualTo(Orientation.Landscape);
}

@Test
public void landscapePortrait_regardedAsUserOrientation() throws Exception {
public void landscapePortrait_regardedAsUserOrientation() {
OrientationOptions options = OrientationOptions.parse(create("landscape", "portrait"));
assertThat(options.getValue()).isEqualTo(Orientation.PortraitLandscape.orientationCode);
}

@Test
public void portraitLandscape_regardedAsUserOrientation() throws Exception {
public void portraitLandscape_regardedAsUserOrientation() {
OrientationOptions options = OrientationOptions.parse(create("portrait", "landscape"));
assertThat(options.getValue()).isEqualTo(Orientation.PortraitLandscape.orientationCode);
}

@Test
public void unsupportedOrientationsAreIgnored() throws Exception {
public void unsupportedOrientationsAreIgnored() {
OrientationOptions options = OrientationOptions.parse(create("default", "autoRotate"));
assertThat(options.orientations).hasSize(1);
assertThat(options.orientations.get(0)).isEqualTo(Orientation.Default);
}

@Test
public void getValue_returnsDefaultIfUndefined() throws Exception {
public void getValue_returnsDefaultIfUndefined() {
OrientationOptions options = new OrientationOptions();
assertThat(options.getValue()).isEqualTo(Orientation.Default.orientationCode);
}

@Test
public void hasValue_returnsFalseForOrientationDefault() {
OrientationOptions options = OrientationOptions.parse(create("default"));
assertThat(options.hasValue()).isFalse();
}

private JSONObject create(String... orientations) {
JSONObject orientation = new JSONObject();
try {
Expand Down
9 changes: 4 additions & 5 deletions playground/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ project.ext.react = [
apply from: "../../../node_modules/react-native/react.gradle"

android {
compileSdkVersion 26
buildToolsVersion "27.0.3"
compileSdkVersion 28

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand All @@ -19,7 +18,7 @@ android {
defaultConfig {
applicationId "com.reactnativenavigation.playground"
minSdkVersion 21
targetSdkVersion 25
targetSdkVersion 28
versionCode 1
versionName "1.0"
ndk {
Expand Down Expand Up @@ -57,8 +56,8 @@ configurations.all {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'

//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+'
Expand Down
3 changes: 2 additions & 1 deletion playground/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ function start() {
Navigation.events().registerAppLaunchedListener(async () => {
Navigation.setDefaultOptions({
layout: {
componentBackgroundColor: '#e8e8e8'
componentBackgroundColor: '#e8e8e8',
orientation: ['portrait']
},
bottomTab: {
iconColor: '#1B4C77',
Expand Down
3 changes: 3 additions & 0 deletions playground/src/screens/WelcomeScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ class WelcomeScreen extends Component {
component: {
name: 'navigation.playground.PushedScreen',
options: {
layout: {

},
topBar: {
title: {
text: 'pushed',
Expand Down

0 comments on commit 43ae659

Please sign in to comment.