Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

[expo-cli][eject] Fix generated orientation in AndroidManifest #2431

Merged
merged 3 commits into from
Aug 7, 2020

Conversation

barthap
Copy link
Contributor

@barthap barthap commented Aug 6, 2020

Fixes #2429

Tested by just ejecting project and checking if orientation in manifest is correct. Also wrote 2 tests and ran jest.

@barthap barthap requested review from wkozyra95 and bbarthec August 6, 2020 11:39
@barthap barthap changed the title @barthap/eject/android orientation [expo-cli][eject] Fix generated orientation in AndroidManifest.xml Aug 6, 2020
@barthap barthap marked this pull request as ready for review August 7, 2020 05:03
Copy link
Contributor

@wkozyra95 wkozyra95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -16,7 +24,7 @@ export async function setAndroidOrientation(config: ExpoConfig, manifestDocument
const mainActivity = manifestDocument.manifest.application[0].activity.filter(
(e: any) => e['$']['android:name'] === '.MainActivity'
);
mainActivity[0]['$'][SCREEN_ORIENTATION_ATTRIBUTE] = orientation;
mainActivity[0]['$'][SCREEN_ORIENTATION_ATTRIBUTE] = prepareOrientation(orientation);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mainActivity[0]['$'][SCREEN_ORIENTATION_ATTRIBUTE] = prepareOrientation(orientation);
mainActivity[0]['$'][SCREEN_ORIENTATION_ATTRIBUTE] = orientation !== 'default' ? orientation : 'unspecified';

nit pick: prepareOrientation might be a bit misleading and implementation is simple enough to just put inline

Copy link
Contributor Author

@barthap barthap Aug 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right - assuming that Expo accepts only 3 values: default, portrait and landscape, and 2 of them are valid manifest values, I can simplify that 😉 I extracted it to external function to make it easier to handle possible future extensions.

@@ -7,6 +7,14 @@ export function getOrientation(config: ExpoConfig) {
return typeof config.orientation === 'string' ? config.orientation : null;
}

export function prepareOrientation(orientation: string) {
if (orientation === 'default') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it's a stupid question, but why you are handling 'default' value differently than missing one?

Copy link
Contributor Author

@barthap barthap Aug 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just because the missing one is already handled when called this function

@bbarthec bbarthec changed the title [expo-cli][eject] Fix generated orientation in AndroidManifest.xml [expo-cli][eject] Fix generated orientation in AndroidManifest Aug 7, 2020
@bbarthec bbarthec merged commit 304128f into master Aug 7, 2020
@bbarthec bbarthec deleted the @barthap/eject/android-orientation branch August 7, 2020 12:12
@dsokal
Copy link
Contributor

dsokal commented Aug 7, 2020

@barthap could you please update the changelog? https://github.com/expo/expo-cli/blob/master/CHANGELOG.md

@bbarthec
Copy link
Contributor

bbarthec commented Aug 7, 2020

CHANGELOG updated here: 274f7bf

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Eject generates invalid activity orientation in AndroidManifest.xml
4 participants