Skip to content
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

[core] add reloadAppAsync support #28400

Merged
merged 8 commits into from May 2, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -16,6 +16,12 @@ export const Screens = [
},
name: 'ExpoModules',
},
{
getComponent() {
return optionalRequire(() => require('../screens/ExpoCoreModuleScreen'));
},
name: 'ExpoCoreModule',
},
{
getComponent() {
return optionalRequire(() => require('../screens/StatusBarScreen'));
Expand Down
1 change: 1 addition & 0 deletions apps/native-component-list/src/screens/ExpoApisScreen.tsx
Expand Up @@ -49,6 +49,7 @@ const screens = [
'FileSystem',
'Font',
'Errors',
'ExpoCoreModule',
'ExpoModules',
'Geocoding',
'Haptics',
Expand Down
23 changes: 23 additions & 0 deletions apps/native-component-list/src/screens/ExpoCoreModuleScreen.tsx
@@ -0,0 +1,23 @@
import { reloadAppAsync } from 'expo';
import { ScrollView, StyleSheet } from 'react-native';

import ListButton from '../components/ListButton';

export default function ExpoCoreModuleScreen() {
return (
<ScrollView style={styles.scrollView}>
<ListButton
title="reloadAppAsync"
onPress={() => {
reloadAppAsync('Reload from ExpoCoreModuleScreen');
}}
/>
</ScrollView>
);
}

const styles = StyleSheet.create({
scrollView: {
padding: 10,
},
});
2 changes: 2 additions & 0 deletions packages/expo-modules-core/CHANGELOG.md
Expand Up @@ -6,6 +6,8 @@

### 🎉 New features

- Introduced the `reloadAppAsync` to reload the app. ([#28400](https://github.com/expo/expo/pull/28400) by [@kudo](https://github.com/kudo))

### 🐛 Bug fixes

### 💡 Others
Expand Down
@@ -1,5 +1,10 @@
package expo.modules.kotlin.defaultmodules

import com.facebook.react.ReactActivity
import com.facebook.react.ReactDelegate
import com.facebook.react.bridge.UiThreadUtil
import com.facebook.react.config.ReactFeatureFlags
import com.facebook.react.devsupport.DisabledDevSupportManager
import expo.modules.kotlin.events.normalizeEventName
import expo.modules.kotlin.modules.Module
import expo.modules.kotlin.modules.ModuleDefinition
Expand Down Expand Up @@ -50,5 +55,30 @@ class CoreModule : Module() {
"directEventTypes" to directEventTypes
)
}

AsyncFunction("reloadAppAsync") { _: String ->
val reactActivity = appContext.currentActivity as? ReactActivity ?: return@AsyncFunction

// TODO(kudo): Use ReactActivity.getReactDelegate() after react-native 0.74.1
// reactActivity.getReactDelegate()
val reactActivityDelegateField = ReactActivity::class.java.getDeclaredField("mDelegate")
.apply { isAccessible = true }
val reactActivityDelegate = reactActivityDelegateField[reactActivity]
val getReactDelegateMethod = reactActivityDelegate.javaClass.getDeclaredMethod("getReactDelegate")
.apply { isAccessible = true }
val reactDelegate = getReactDelegateMethod.invoke(reactActivityDelegate) as? ReactDelegate
?: return@AsyncFunction
if (!ReactFeatureFlags.enableBridgelessArchitecture) {
val reactInstanceManager = reactDelegate.reactInstanceManager
if (reactInstanceManager.devSupportManager is DisabledDevSupportManager) {
UiThreadUtil.runOnUiThread {
reactInstanceManager.recreateReactContextInBackground()
}
return@AsyncFunction
}
}

reactDelegate.reload()
}
}
}
1 change: 1 addition & 0 deletions packages/expo-modules-core/build/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-modules-core/build/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/expo-modules-core/build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-modules-core/build/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions packages/expo-modules-core/build/reload.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/expo-modules-core/build/reload.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions packages/expo-modules-core/build/reload.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/expo-modules-core/build/reload.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/expo-modules-core/build/web/CoreModule.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.