-
Notifications
You must be signed in to change notification settings - Fork 935
feat: read main activity from AndroidManifest.xml automatically
#1967
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thymikee
merged 6 commits into
react-native-community:main
from
szymonrybczak:feat/readMainActivityAutomatically
Aug 17, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e16ff7e
feat: read main activity from `AndroidManifest.xml` automatically
szymonrybczak 1704481
test: update e2e snaphosts
szymonrybczak 900f5f0
test: add test scenario for main activity as class name
szymonrybczak a7168ba
chore: types cleanup
szymonrybczak 5cd2e45
chore: code cleaning
szymonrybczak 925eceb
fix: tests
szymonrybczak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/cli-platform-android/src/config/__fixtures__/files/AndroidManifest-className.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.some.example"> | ||
| <uses-permission android:name="android.permission.INTERNET" /> | ||
|
|
||
| <application android:name=".MainApplication"> | ||
| <activity android:name="com.example.ExampleAppActivity"> | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.MAIN" /> | ||
| <category android:name="android.intent.category.LAUNCHER" /> | ||
| </intent-filter> | ||
| </activity> | ||
| </application> | ||
| </manifest> |
20 changes: 20 additions & 0 deletions
20
...ges/cli-platform-android/src/config/__fixtures__/files/AndroidManifest-few-activities.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <manifest | ||
| xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| <application android:name=".ExampleApplication"> | ||
| <activity android:name=".ExampleAppActivity"> | ||
szymonrybczak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <intent-filter> | ||
| <action android:name="android.intent.action.MAIN" /> | ||
| <category android:name="android.intent.category.LAUNCHER" /> | ||
| <category android:name="android.intent.category.LEANBACK_LAUNCHER" /> | ||
| </intent-filter> | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.VIEW" /> | ||
| <category android:name="android.intent.category.DEFAULT" /> | ||
| <category android:name="android.intent.category.BROWSABLE" /> | ||
| <data android:scheme="rntester" android:host="example" /> | ||
| </intent-filter> | ||
| </activity> | ||
| <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false"/> | ||
| </application> | ||
| </queries> | ||
| </manifest> | ||
14 changes: 11 additions & 3 deletions
14
packages/cli-platform-android/src/config/__fixtures__/files/AndroidManifest.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,12 @@ | ||
| <manifest | ||
| xmlns:android="http://schemas.android.com/apk/res/android" | ||
| package="com.some.example"> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.some.example"> | ||
| <uses-permission android:name="android.permission.INTERNET" /> | ||
|
|
||
| <application android:name=".MainApplication"> | ||
| <activity android:name=".MainActivity"> | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.MAIN" /> | ||
| <category android:name="android.intent.category.LAUNCHER" /> | ||
| </intent-filter> | ||
| </activity> | ||
| </application> | ||
| </manifest> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/cli-platform-android/src/config/__tests__/getMainActivity.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import findManifest from '../findManifest'; | ||
| import getMainActivity from '../getMainActivity'; | ||
| import * as mocks from '../__fixtures__/android'; | ||
|
|
||
| jest.mock('path'); | ||
| jest.mock('fs'); | ||
|
|
||
| const fs = require('fs'); | ||
|
|
||
| describe('android::getMainActivity', () => { | ||
| beforeAll(() => { | ||
| fs.__setMockFilesystem({ | ||
| empty: {}, | ||
| valid: { | ||
| android: { | ||
| app: mocks.valid, | ||
| }, | ||
| }, | ||
| className: { | ||
| android: { | ||
| app: mocks.className, | ||
| }, | ||
| }, | ||
| few: { | ||
| android: { | ||
| app: mocks.fewActivities, | ||
| }, | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('returns main activity if file exists in the folder', () => { | ||
| const manifestPath = findManifest('/valid'); | ||
| const manifest = getMainActivity(manifestPath || ''); | ||
| expect(manifest).not.toBeNull(); | ||
| expect(typeof manifest).toBe('string'); | ||
| expect(manifest).toBe('.MainActivity'); | ||
| }); | ||
|
|
||
| it('returns main activity if there is few activities', () => { | ||
| const manifestPath = findManifest('/few'); | ||
| const mainActivity = getMainActivity(manifestPath || ''); | ||
| expect(mainActivity).not.toBeNull(); | ||
| expect(typeof mainActivity).toBe('string'); | ||
| expect(mainActivity).toBe('.ExampleAppActivity'); | ||
| }); | ||
|
|
||
| it('returns main activity if it is class name', () => { | ||
| const manifestPath = findManifest('/className'); | ||
| const mainActivity = getMainActivity(manifestPath || ''); | ||
| expect(mainActivity).not.toBeNull(); | ||
| expect(typeof mainActivity).toBe('string'); | ||
| expect(mainActivity).toBe('com.example.ExampleAppActivity'); | ||
| }); | ||
|
|
||
| it('returns null if file do not exist', () => { | ||
| const fakeManifestPath = findManifest('/empty'); | ||
| expect(getMainActivity(fakeManifestPath || '')).toBeNull(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.