Skip to content

Expo: initialize batch module from main application #10

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
merged 5 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '17'
node-version: '18'
cache: 'yarn'
- name: Install dependencies
run: yarn
- name: Test
run: yarn test
- name: Lint
run: yarn lint
run: yarn lint
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '17'
node-version: '18'
cache: 'yarn'
# Disable eslint annotations, which are already appended by the build action
- run: |
echo "::remove-matcher owner=eslint-compact::"
echo "::remove-matcher owner=eslint-stylish::"
- name: Install dependencies
run: yarn
# TODO: Remplace this with a github action that parses the output of eslint
# TODO: Replace this with a github action that parses the output of eslint
# and annotates the files: this step doesn't have all annotations working
# Or, wait for github to fix it.
- name: Lint
run: yarn lint:fail-on-warnings
run: yarn lint:fail-on-warnings
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '17'
node-version: '18'
cache: 'yarn'
registry-url: https://registry.npmjs.org/
- name: Install dependencies
run: yarn
- name: Test
run: yarn test
- name: Lint
run: yarn lint
run: yarn lint
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
- name: Documentation
run: yarn doc:deploy
run: yarn doc:deploy
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
UPCOMING
----

**Expo**

* Fixed an issue where Batch could miss the first activity start.

9.0.1
----

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
"eslint": "^8.16.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"expo-module-scripts": "^2.0.0",
"expo-module-scripts": "^3.5.2",
"jest": "^27.3.1",
"prettier": "^1.14.2",
"react-native": "^0.66.1",
"ts-jest": "^27.0.7",
"typedoc": "^0.22.7",
"typescript": "^4.7.2"
"typescript": "^5.5.3"
}
}
59 changes: 59 additions & 0 deletions plugin/src/android/withReactNativeBatchMainApplication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { ConfigPlugin, withMainApplication } from '@expo/config-plugins';

export const modifyMainJavaApplication = (content: string): string => {
let newContent = content;
if (newContent.includes('import com.facebook.react.PackageList;')) {
newContent = content.replace(
'import com.facebook.react.PackageList;',
`import com.batch.batch_rn.RNBatchModule;
import com.facebook.react.PackageList;`
);
}
if (newContent.includes('ApplicationLifecycleDispatcher.onApplicationCreate(this)')) {
newContent = newContent.replace(
'ApplicationLifecycleDispatcher.onApplicationCreate(this);',
`ApplicationLifecycleDispatcher.onApplicationCreate(this);
RNBatchModule.initialize(this);`
);
}
return newContent;
};

export const modifyMainKotlinApplication = (content: string): string => {
let newContent = content;
if (newContent.includes('import com.facebook.react.PackageList')) {
newContent = content.replace(
'import com.facebook.react.PackageList',
`import com.batch.batch_rn.RNBatchModule
import com.facebook.react.PackageList`
);
}
if (newContent.includes('ApplicationLifecycleDispatcher.onApplicationCreate(this)')) {
newContent = newContent.replace(
'ApplicationLifecycleDispatcher.onApplicationCreate(this)',
`ApplicationLifecycleDispatcher.onApplicationCreate(this)
RNBatchModule.initialize(this)`
);
}
return newContent;
};

export const modifyMainApplication = (content: string): string => {
return isKotlinMainApplication(content) ? modifyMainKotlinApplication(content) : modifyMainJavaApplication(content);
};

const isKotlinMainApplication = (content: string): boolean => {
return content.includes('class MainApplication : Application(), ReactApplication');
};

export const withReactNativeBatchMainApplication: ConfigPlugin<object | void> = config => {
return withMainApplication(config, config => {
return {
...config,
modResults: {
...config.modResults,
contents: modifyMainApplication(config.modResults.contents),
},
};
});
};
2 changes: 2 additions & 0 deletions plugin/src/withReactNativeBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { withClassPath, withApplyPlugin, withGoogleServicesFile } from '@expo/co

import { withReactNativeBatchAppBuildGradle } from './android/withReactNativeBatchAppBuildGradle';
import { withReactNativeBatchMainActivity } from './android/withReactNativeBatchMainActivity';
import { withReactNativeBatchMainApplication } from './android/withReactNativeBatchMainApplication';
import { withReactNativeBatchManifest } from './android/withReactNativeBatchManifest';
import { withReactNativeBatchAppDelegate } from './ios/withReactNativeBatchAppDelegate';
import { withReactNativeBatchInfoPlist } from './ios/withReactNativeBatchInfoPlist';
Expand All @@ -26,6 +27,7 @@ const withReactNativeBatch: ConfigPlugin<Props | void> = (config, props) => {
newConfig = withApplyPlugin(newConfig);
newConfig = withReactNativeBatchManifest(newConfig, _props);
newConfig = withReactNativeBatchAppBuildGradle(newConfig, _props);
newConfig = withReactNativeBatchMainApplication(newConfig);
newConfig = withReactNativeBatchMainActivity(newConfig);
newConfig = withReactNativeBatchInfoPlist(newConfig, _props);
newConfig = withReactNativeBatchAppDelegate(newConfig);
Expand Down
Loading
Loading