Skip to content

Commit ca4f5e2

Browse files
StevenSteven
authored andcommitted
support to expo
1 parent 6fb654f commit ca4f5e2

File tree

21 files changed

+17700
-21
lines changed

21 files changed

+17700
-21
lines changed

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
18

Example/testHotUpdate/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
18

Example/testHotUpdate/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
"react-native-paper": "^5.13.1",
2323
"react-native-safe-area-context": "^5.3.0",
2424
"react-native-svg": "^15.11.2",
25-
"react-native-update": "^10.26.4",
26-
"react-native-vector-icons": "^10.2.0"
25+
"react-native-vector-icons": "^10.2.0",
26+
"react-native-update": "file:../../"
2727
},
2828
"devDependencies": {
2929
"@babel/core": "^7.26.0",

Example/testHotUpdate/src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ function App() {
5353
return (
5454
<View style={styles.container}>
5555
<Text style={styles.welcome}>欢迎使用Pushy热更新服务</Text>
56+
<Text style={styles.welcome}>😁热更新成功</Text>
5657
<View style={{flexDirection: 'row'}}>
5758
<Text>
5859
{useDefaultAlert ? '当前使用' : '当前不使用'}默认的alert更新提示

Example/testHotUpdate/update.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"appKey": "SqShg4Klnj2hG6LAFMW2PdcgSSuniz0T"
55
},
66
"android": {
7-
"appId": 27509,
8-
"appKey": "aQz3Uc2pA7gt_prDaQ4rbWRY"
7+
"appId": 29041,
8+
"appKey": "z9QWhywEiBMaE93ZBk42jqlz"
99
}
1010
}

Example/testHotUpdate/yarn.lock

Lines changed: 7566 additions & 0 deletions
Large diffs are not rendered by default.

android/build.gradle

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,42 @@ def supportsNamespace() {
2222
return major >= 8
2323
}
2424

25+
def isExpoProject() {
26+
def hasExpoModulesCore = rootProject.subprojects.any { it.name == 'expo-modules-core' }
27+
28+
def packageJsonFile = new File(rootProject.projectDir.parentFile, 'package.json')
29+
def hasExpoDependency = false
30+
if (packageJsonFile.exists()) {
31+
def packageJson = new groovy.json.JsonSlurper().parseText(packageJsonFile.text)
32+
hasExpoDependency = (packageJson.dependencies?.expo != null) ||
33+
(packageJson.devDependencies?.expo != null)
34+
}
35+
36+
return hasExpoModulesCore || hasExpoDependency
37+
}
38+
39+
def expoProject = isExpoProject()
40+
2541
apply plugin: 'com.android.library'
2642
if (isNewArchitectureEnabled()) {
2743
apply plugin: 'com.facebook.react'
2844
}
2945

46+
if (expoProject) {
47+
group = 'expo.modules.pushy'
48+
version = '1.0.0'
3049

31-
android {
50+
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
51+
apply from: expoModulesCorePlugin
52+
applyKotlinExpoModulesCorePlugin()
53+
useCoreDependencies()
54+
useExpoPublishing()
55+
} else {
56+
group = 'cn.reactnative.modules.update'
57+
version = '1.0.0'
58+
}
3259

60+
android {
3361
if (supportsNamespace()) {
3462
namespace "cn.reactnative.modules.update"
3563

@@ -41,7 +69,6 @@ android {
4169
}
4270
compileSdkVersion safeExtGet('compileSdkVersion', 28)
4371
buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')
44-
4572
defaultConfig {
4673
minSdkVersion safeExtGet('minSdkVersion', 16)
4774
targetSdkVersion safeExtGet('targetSdkVersion', 27)
@@ -50,6 +77,7 @@ android {
5077
consumerProguardFiles "proguard.pro"
5178
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
5279
}
80+
5381
sourceSets {
5482
main {
5583
// let gradle pack the shared library into apk
@@ -59,17 +87,28 @@ android {
5987
} else {
6088
java.srcDirs += ['src/oldarch']
6189
}
90+
91+
if (expoProject) {
92+
java.srcDirs += ['java/expo/modules/pushy']
93+
} else {
94+
java.exclude 'expo/modules/pushy/**'
95+
}
6296
}
6397
}
6498

6599
buildTypes {
66100
release {
67-
resValue("string", "pushy_build_time", "${minutesSinceEpoch}")
101+
// resValue("string", "pushy_build_time", "${minutesSinceEpoch}")
102+
resValue("string", "pushy_build_time", "29042093")
68103
}
69104
debug {
70105
resValue("string", "pushy_build_time", "0")
71106
}
72107
}
108+
109+
lintOptions {
110+
abortOnError false
111+
}
73112
}
74113

75114
repositories {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package cn.reactnative.modules.update;
2+
3+
import androidx.annotation.Nullable;
4+
5+
public interface ReactNativeHostHandler {
6+
@Nullable
7+
String getJSBundleFile(boolean useDeveloperSupport);
8+
9+
@Nullable
10+
String getBundleAssetName(boolean useDeveloperSupport);
11+
12+
void onWillCreateReactInstance(boolean useDeveloperSupport);
13+
}

android/src/main/java/cn/reactnative/modules/update/UpdateContext.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@
77
import android.os.Build;
88
import android.os.Environment;
99
import android.util.Log;
10-
1110
import com.facebook.react.ReactInstanceManager;
12-
1311
import java.util.HashMap;
1412
import java.util.Map;
1513
import java.util.concurrent.Executor;
1614
import java.util.concurrent.Executors;
17-
1815
import java.io.File;
1916

2017
public class UpdateContext {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package expo.modules.pushy
2+
3+
import expo.modules.kotlin.modules.Module
4+
import expo.modules.kotlin.modules.ModuleDefinition
5+
import java.net.URL
6+
7+
class ExpoPushyModule : Module() {
8+
// Each module class must implement the definition function. The definition consists of components
9+
// that describes the module's functionality and behavior.
10+
// See https://docs.expo.dev/modules/module-api for more details about available components.
11+
override fun definition() = ModuleDefinition {
12+
// Sets the name of the module that JavaScript code will use to refer to the module. Takes a string as an argument.
13+
// Can be inferred from module's class name, but it's recommended to set it explicitly for clarity.
14+
// The module will be accessible from `requireNativeModule('ExpoPushy')` in JavaScript.
15+
Name("ExpoPushy")
16+
17+
// Sets constant properties on the module. Can take a dictionary or a closure that returns a dictionary.
18+
Constants(
19+
"PI" to Math.PI
20+
)
21+
22+
// Defines event names that the module can send to JavaScript.
23+
Events("onChange")
24+
25+
// Defines a JavaScript synchronous function that runs the native code on the JavaScript thread.
26+
Function("hello") {
27+
"Hello world! 👋"
28+
}
29+
30+
// Defines a JavaScript function that always returns a Promise and whose native code
31+
// is by default dispatched on the different thread than the JavaScript runtime runs on.
32+
AsyncFunction("setValueAsync") { value: String ->
33+
// Send an event to JavaScript.
34+
sendEvent("onChange", mapOf(
35+
"value" to value
36+
))
37+
}
38+
39+
// Enables the module to be used as a native view. Definition components that are accepted as part of
40+
// the view definition: Prop, Events.
41+
View(ExpoPushyView::class) {
42+
// Defines a setter for the `url` prop.
43+
Prop("url") { view: ExpoPushyView, url: URL ->
44+
view.webView.loadUrl(url.toString())
45+
}
46+
// Defines an event that the view can send to JavaScript.
47+
Events("onLoad")
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)