Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
1 change: 1 addition & 0 deletions Example/testHotUpdate/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
4 changes: 2 additions & 2 deletions Example/testHotUpdate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"react-native-paper": "^5.13.1",
"react-native-safe-area-context": "^5.3.0",
"react-native-svg": "^15.11.2",
"react-native-update": "^10.26.4",
"react-native-vector-icons": "^10.2.0"
"react-native-vector-icons": "^10.2.0",
"react-native-update": "file:../../"
},
"devDependencies": {
"@babel/core": "^7.26.0",
Expand Down
1 change: 1 addition & 0 deletions Example/testHotUpdate/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function App() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>欢迎使用Pushy热更新服务</Text>
<Text style={styles.welcome}>😁热更新成功</Text>
<View style={{flexDirection: 'row'}}>
<Text>
{useDefaultAlert ? '当前使用' : '当前不使用'}默认的alert更新提示
Expand Down
4 changes: 2 additions & 2 deletions Example/testHotUpdate/update.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"appKey": "SqShg4Klnj2hG6LAFMW2PdcgSSuniz0T"
},
"android": {
"appId": 27509,
"appKey": "aQz3Uc2pA7gt_prDaQ4rbWRY"
"appId": 29041,
"appKey": "z9QWhywEiBMaE93ZBk42jqlz"
}
}
7,566 changes: 7,566 additions & 0 deletions Example/testHotUpdate/yarn.lock

Large diffs are not rendered by default.

45 changes: 42 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,42 @@ def supportsNamespace() {
return major >= 8
}

def isExpoProject() {
def hasExpoModulesCore = rootProject.subprojects.any { it.name == 'expo-modules-core' }

def packageJsonFile = new File(rootProject.projectDir.parentFile, 'package.json')
def hasExpoDependency = false
if (packageJsonFile.exists()) {
def packageJson = new groovy.json.JsonSlurper().parseText(packageJsonFile.text)
hasExpoDependency = (packageJson.dependencies?.expo != null) ||
(packageJson.devDependencies?.expo != null)
}

return hasExpoModulesCore || hasExpoDependency
}

def expoProject = isExpoProject()

apply plugin: 'com.android.library'
if (isNewArchitectureEnabled()) {
apply plugin: 'com.facebook.react'
}

if (expoProject) {
group = 'expo.modules.pushy'
version = '1.0.0'

android {
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
apply from: expoModulesCorePlugin
applyKotlinExpoModulesCorePlugin()
useCoreDependencies()
useExpoPublishing()
} else {
group = 'cn.reactnative.modules.update'
version = '1.0.0'
}

android {
if (supportsNamespace()) {
namespace "cn.reactnative.modules.update"

Expand All @@ -41,7 +69,6 @@ android {
}
compileSdkVersion safeExtGet('compileSdkVersion', 28)
buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')

defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 16)
targetSdkVersion safeExtGet('targetSdkVersion', 27)
Expand All @@ -50,6 +77,7 @@ android {
consumerProguardFiles "proguard.pro"
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
}

sourceSets {
main {
// let gradle pack the shared library into apk
Expand All @@ -59,17 +87,28 @@ android {
} else {
java.srcDirs += ['src/oldarch']
}

if (expoProject) {
java.srcDirs += ['java/expo/modules/pushy']
} else {
java.exclude 'expo/modules/pushy/**'
}
}
}

buildTypes {
release {
resValue("string", "pushy_build_time", "${minutesSinceEpoch}")
// resValue("string", "pushy_build_time", "${minutesSinceEpoch}")
resValue("string", "pushy_build_time", "29042093")
}
debug {
resValue("string", "pushy_build_time", "0")
}
}

lintOptions {
abortOnError false
}
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cn.reactnative.modules.update;

import androidx.annotation.Nullable;

public interface ReactNativeHostHandler {
@Nullable
String getJSBundleFile(boolean useDeveloperSupport);

@Nullable
String getBundleAssetName(boolean useDeveloperSupport);

void onWillCreateReactInstance(boolean useDeveloperSupport);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@
import android.os.Build;
import android.os.Environment;
import android.util.Log;

import com.facebook.react.ReactInstanceManager;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

import java.io.File;

public class UpdateContext {
Expand Down
50 changes: 50 additions & 0 deletions android/src/main/java/expo/modules/pushy/ExpoPushyModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package expo.modules.pushy

import expo.modules.kotlin.modules.Module
import expo.modules.kotlin.modules.ModuleDefinition
import java.net.URL

class ExpoPushyModule : Module() {
// Each module class must implement the definition function. The definition consists of components
// that describes the module's functionality and behavior.
// See https://docs.expo.dev/modules/module-api for more details about available components.
override fun definition() = ModuleDefinition {
// Sets the name of the module that JavaScript code will use to refer to the module. Takes a string as an argument.
// Can be inferred from module's class name, but it's recommended to set it explicitly for clarity.
// The module will be accessible from `requireNativeModule('ExpoPushy')` in JavaScript.
Name("ExpoPushy")

// Sets constant properties on the module. Can take a dictionary or a closure that returns a dictionary.
Constants(
"PI" to Math.PI
)

// Defines event names that the module can send to JavaScript.
Events("onChange")

// Defines a JavaScript synchronous function that runs the native code on the JavaScript thread.
Function("hello") {
"Hello world! 👋"
}

// Defines a JavaScript function that always returns a Promise and whose native code
// is by default dispatched on the different thread than the JavaScript runtime runs on.
AsyncFunction("setValueAsync") { value: String ->
// Send an event to JavaScript.
sendEvent("onChange", mapOf(
"value" to value
))
}

// Enables the module to be used as a native view. Definition components that are accepted as part of
// the view definition: Prop, Events.
View(ExpoPushyView::class) {
// Defines a setter for the `url` prop.
Prop("url") { view: ExpoPushyView, url: URL ->
view.webView.loadUrl(url.toString())
}
// Defines an event that the view can send to JavaScript.
Events("onLoad")
}
}
}
28 changes: 28 additions & 0 deletions android/src/main/java/expo/modules/pushy/ExpoPushyPackage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package expo.modules.pushy;

import android.content.Context;
import android.util.Log;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.reactnative.modules.update.UpdateContext;
import expo.modules.core.interfaces.Package;
import expo.modules.core.interfaces.ReactNativeHostHandler;

public class ExpoPushyPackage implements Package {
@Override
public List<ReactNativeHostHandler> createReactNativeHostHandlers(Context context) {
List<ReactNativeHostHandler> handlers = new ArrayList<>();
handlers.add(new ReactNativeHostHandler() {
@Nullable
@Override
public String getJSBundleFile(boolean useDeveloperSupport) {
String bundleUrl = UpdateContext.getBundleUrl(context);
return bundleUrl;
}
});
return handlers;
}
}
30 changes: 30 additions & 0 deletions android/src/main/java/expo/modules/pushy/ExpoPushyView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package expo.modules.pushy

import android.content.Context
import android.webkit.WebView
import android.webkit.WebViewClient
import expo.modules.kotlin.AppContext
import expo.modules.kotlin.viewevent.EventDispatcher
import expo.modules.kotlin.views.ExpoView

class ExpoPushyView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
// Creates and initializes an event dispatcher for the `onLoad` event.
// The name of the event is inferred from the value and needs to match the event name defined in the module.
private val onLoad by EventDispatcher()

// Defines a WebView that will be used as the root subview.
internal val webView = WebView(context).apply {
layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
webViewClient = object : WebViewClient() {
override fun onPageFinished(view: WebView, url: String) {
// Sends an event to JavaScript. Triggers a callback defined on the view component in JavaScript.
onLoad(mapOf("url" to url))
}
}
}

init {
// Adds the WebView to the view hierarchy.
addView(webView)
}
}
1 change: 1 addition & 0 deletions app.plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('react-native-update/plugin/withUpdate');
13 changes: 13 additions & 0 deletions expo-module.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"platforms": ["apple", "android"],
"apple": {
"modules": ["ExpoPushyModule"],
"reactDelegateHandlers": ["ExpoPushyReactDelegateHandler"],
"podspec": "./ExpoPushy.podspec"
},
"android": {
"modules": [
"expo.modules.pushy.ExpoPushyModule"
]
}
}
71 changes: 71 additions & 0 deletions ios/ExpoPushy.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
require 'json'

new_arch_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1'

package = JSON.parse(File.read(File.join(__dir__, '../package.json')))

podspec_dir = File.dirname(__FILE__)

Pod::Spec.new do |s|
s.name = 'ExpoPushy'
s.version = package['version']
s.summary = package['description']
s.license = package['license']

s.authors = package['author']
s.homepage = package['homepage']

s.cocoapods_version = '>= 1.6.0'
s.platform = :ios, "8.0"
s.platforms = { :ios => "11.0" }
s.source = { :git => 'https://github.com/reactnativecn/react-native-update.git', :tag => '#{s.version}' }
s.source_files = "**/*.{h,m,mm,swift}"
s.libraries = 'bz2', 'z'
s.vendored_libraries = 'RCTPushy/libRCTPushy.a'
s.pod_target_xcconfig = {
'USER_HEADER_SEARCH_PATHS' => "#{podspec_dir}",
"DEFINES_MODULE" => "YES"
}
s.resource = 'pushy_build_time.txt'
s.script_phase = { :name => 'Generate build time', :script => "set -x;date +%s > \"#{podspec_dir}/pushy_build_time.txt\"", :execution_position => :before_compile }

s.dependency 'React'
s.dependency "React-Core"
s.dependency 'SSZipArchive'
s.dependency 'ExpoModulesCore'

s.subspec 'RCTPushy' do |ss|
ss.source_files = 'RCTPushy/*.{h,m,mm,swift}'
ss.public_header_files = ['RCTPushy/RCTPushy.h']
end

s.subspec 'HDiffPatch' do |ss|
ss.source_files = ['RCTPushy/HDiffPatch/**/*.{h,m,c}',
'iOS/../android/jni/hpatch.{h,c}',
'iOS/../android/jni/HDiffPatch/libHDiffPatch/HPatch/*.{h,c}',
'iOS/../android/jni/HDiffPatch/file_for_patch.{h,c}',
'iOS/../android/jni/lzma/C/LzmaDec.{h,c}',
'iOS/../android/jni/lzma/C/Lzma2Dec.{h,c}']
ss.public_header_files = 'RCTPushy/HDiffPatch/**/*.h'
end

if defined?(install_modules_dependencies()) != nil
install_modules_dependencies(s);
else
if new_arch_enabled
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'

s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"

s.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
}
s.dependency "React-Codegen"
s.dependency "RCT-Folly"
s.dependency "RCTRequired"
s.dependency "RCTTypeSafety"
s.dependency "ReactCommon/turbomodule/core"
end
end
end
Loading