mirror of
				https://gitcode.com/gh_mirrors/re/react-native-pushy.git
				synced 2025-10-31 21:33:12 +08:00 
			
		
		
		
	support to Expo (#486)
* support to Expo * update * update * update --------- Co-authored-by: Steven <steven@Stevens-MacBook-Pro.local>
This commit is contained in:
		
							
								
								
									
										7566
									
								
								Example/testHotUpdate/yarn.lock
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7566
									
								
								Example/testHotUpdate/yarn.lock
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -22,14 +22,42 @@ def supportsNamespace() { | |||||||
|   return major >= 8 |   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' | apply plugin: 'com.android.library' | ||||||
| if (isNewArchitectureEnabled()) { | if (isNewArchitectureEnabled()) { | ||||||
|     apply plugin: 'com.facebook.react' |     apply plugin: 'com.facebook.react' | ||||||
| } | } | ||||||
|  |  | ||||||
|  | if (expoProject) { | ||||||
|  |     group = 'expo.modules.pushy' | ||||||
|  |     version = '1.0.0' | ||||||
|  |  | ||||||
|  |     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 { | android { | ||||||
|  |  | ||||||
|     if (supportsNamespace()) { |     if (supportsNamespace()) { | ||||||
|         namespace "cn.reactnative.modules.update" |         namespace "cn.reactnative.modules.update" | ||||||
|  |  | ||||||
| @@ -41,7 +69,6 @@ android { | |||||||
|     } |     } | ||||||
|     compileSdkVersion safeExtGet('compileSdkVersion', 28) |     compileSdkVersion safeExtGet('compileSdkVersion', 28) | ||||||
|     buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3') |     buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3') | ||||||
|  |  | ||||||
|     defaultConfig { |     defaultConfig { | ||||||
|         minSdkVersion safeExtGet('minSdkVersion', 16) |         minSdkVersion safeExtGet('minSdkVersion', 16) | ||||||
|         targetSdkVersion safeExtGet('targetSdkVersion', 27) |         targetSdkVersion safeExtGet('targetSdkVersion', 27) | ||||||
| @@ -50,6 +77,7 @@ android { | |||||||
|         consumerProguardFiles "proguard.pro" |         consumerProguardFiles "proguard.pro" | ||||||
|         buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() |         buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() | ||||||
|     } |     } | ||||||
|  |      | ||||||
|     sourceSets { |     sourceSets { | ||||||
|         main { |         main { | ||||||
|             // let gradle pack the shared library into apk |             // let gradle pack the shared library into apk | ||||||
| @@ -59,6 +87,12 @@ android { | |||||||
|             } else { |             } else { | ||||||
|                 java.srcDirs += ['src/oldarch'] |                 java.srcDirs += ['src/oldarch'] | ||||||
|             } |             } | ||||||
|  |              | ||||||
|  |             if (expoProject) { | ||||||
|  |                 java.srcDirs += ['java/expo/modules/pushy'] | ||||||
|  |             } else { | ||||||
|  |                 java.exclude 'expo/modules/pushy/**' | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -70,6 +104,10 @@ android { | |||||||
|             resValue("string", "pushy_build_time", "0") |             resValue("string", "pushy_build_time", "0") | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |      | ||||||
|  |     lintOptions { | ||||||
|  |         abortOnError false | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| repositories { | repositories { | ||||||
|   | |||||||
| @@ -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); | ||||||
|  | }  | ||||||
| @@ -7,14 +7,11 @@ import android.content.pm.PackageManager; | |||||||
| import android.os.Build; | import android.os.Build; | ||||||
| import android.os.Environment; | import android.os.Environment; | ||||||
| import android.util.Log; | import android.util.Log; | ||||||
|  |  | ||||||
| import com.facebook.react.ReactInstanceManager; | import com.facebook.react.ReactInstanceManager; | ||||||
|  |  | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| import java.util.concurrent.Executor; | import java.util.concurrent.Executor; | ||||||
| import java.util.concurrent.Executors; | import java.util.concurrent.Executors; | ||||||
|  |  | ||||||
| import java.io.File; | import java.io.File; | ||||||
|  |  | ||||||
| public class UpdateContext { | public class UpdateContext { | ||||||
|   | |||||||
							
								
								
									
										10
									
								
								android/src/main/java/expo/modules/pushy/ExpoPushyModule.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								android/src/main/java/expo/modules/pushy/ExpoPushyModule.kt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | |||||||
|  | package expo.modules.pushy | ||||||
|  |  | ||||||
|  | import expo.modules.kotlin.modules.Module | ||||||
|  | import expo.modules.kotlin.modules.ModuleDefinition | ||||||
|  |  | ||||||
|  | class ExpoPushyModule : Module() { | ||||||
|  |   override fun definition() = ModuleDefinition { | ||||||
|  |     Name("ExpoPushy") | ||||||
|  |   } | ||||||
|  | } | ||||||
| @@ -0,0 +1,27 @@ | |||||||
|  | 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) { | ||||||
|  |                 return UpdateContext.getBundleUrl(context); | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|  |         return handlers; | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										13
									
								
								expo-module.config.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								expo-module.config.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | |||||||
|  | { | ||||||
|  |  "platforms": ["apple", "android"], | ||||||
|  |   "apple": { | ||||||
|  |     "modules": ["ExpoPushyModule"], | ||||||
|  |     "reactDelegateHandlers": ["ExpoPushyReactDelegateHandler"], | ||||||
|  |     "podspecPath":"react-native-update.podspec" | ||||||
|  |   }, | ||||||
|  |   "android": { | ||||||
|  |     "modules": [ | ||||||
|  |       "expo.modules.pushy.ExpoPushyModule" | ||||||
|  |     ] | ||||||
|  |   } | ||||||
|  | } | ||||||
							
								
								
									
										7
									
								
								ios/Expo/ExpoPushyModule.swift
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								ios/Expo/ExpoPushyModule.swift
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | |||||||
|  | import ExpoModulesCore | ||||||
|  |  | ||||||
|  | public class ExpoPushyModule: Module { | ||||||
|  |   public func definition() -> ModuleDefinition { | ||||||
|  |     Name("ExpoPushy") | ||||||
|  |   } | ||||||
|  | } | ||||||
							
								
								
									
										10
									
								
								ios/Expo/ExpoPushyReactDelegateHandler.swift
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								ios/Expo/ExpoPushyReactDelegateHandler.swift
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | |||||||
|  | import ExpoModulesCore | ||||||
|  | import react_native_update | ||||||
|  |  | ||||||
|  | public final class ExpoPushyReactDelegateHandler: ExpoReactDelegateHandler { | ||||||
|  |   private weak var reactDelegate: ExpoReactDelegate? | ||||||
|  |  | ||||||
|  |   public override func bundleURL(reactDelegate: ExpoReactDelegate) -> URL? { | ||||||
|  |     return  RCTPushy.bundleURL() | ||||||
|  |   } | ||||||
|  | } | ||||||
| @@ -19,7 +19,7 @@ Pod::Spec.new do |s| | |||||||
|   s.platform = :ios, "8.0" |   s.platform = :ios, "8.0" | ||||||
|   s.platforms = { :ios => "11.0" } |   s.platforms = { :ios => "11.0" } | ||||||
|   s.source = { :git => 'https://github.com/reactnativecn/react-native-update.git', :tag => '#{s.version}' } |   s.source = { :git => 'https://github.com/reactnativecn/react-native-update.git', :tag => '#{s.version}' } | ||||||
|   s.source_files    = "ios/**/*.{h,m,mm,swift}" |   s.source_files    = Dir.glob("ios/**/*.{h,m,mm,swift}").reject { |f| f.start_with?("ios/Expo/") } | ||||||
|   s.libraries = 'bz2', 'z' |   s.libraries = 'bz2', 'z' | ||||||
|   s.vendored_libraries = 'RCTPushy/libRCTPushy.a' |   s.vendored_libraries = 'RCTPushy/libRCTPushy.a' | ||||||
|   s.pod_target_xcconfig = {  |   s.pod_target_xcconfig = {  | ||||||
| @@ -33,6 +33,20 @@ Pod::Spec.new do |s| | |||||||
|   s.dependency "React-Core" |   s.dependency "React-Core" | ||||||
|   s.dependency 'SSZipArchive' |   s.dependency 'SSZipArchive' | ||||||
|  |  | ||||||
|  |   project_root = File.expand_path('../../', __dir__) | ||||||
|  |   project_package_json = File.join(project_root, 'package.json') | ||||||
|  |   is_expo_project = false | ||||||
|  |  | ||||||
|  |   if (File.exist?(project_package_json)) | ||||||
|  |     package_json = JSON.parse(File.read(project_package_json)) | ||||||
|  |     has_expo_dependency = package_json['dependencies'] && package_json['dependencies']['expo'] | ||||||
|  |     has_expo_modules_core = Dir.exist?('node_modules/expo-modules-core') | ||||||
|  |     is_expo_project = has_expo_dependency || has_expo_modules_core | ||||||
|  |     if is_expo_project | ||||||
|  |       s.dependency 'ExpoModulesCore' | ||||||
|  |     end | ||||||
|  |   end | ||||||
|  |  | ||||||
|   s.subspec 'RCTPushy' do |ss| |   s.subspec 'RCTPushy' do |ss| | ||||||
|     ss.source_files = 'ios/RCTPushy/*.{h,m,mm,swift}' |     ss.source_files = 'ios/RCTPushy/*.{h,m,mm,swift}' | ||||||
|     ss.public_header_files = ['ios/RCTPushy/RCTPushy.h'] |     ss.public_header_files = ['ios/RCTPushy/RCTPushy.h'] | ||||||
| @@ -48,6 +62,12 @@ Pod::Spec.new do |s| | |||||||
|     ss.public_header_files = 'ios/RCTPushy/HDiffPatch/**/*.h' |     ss.public_header_files = 'ios/RCTPushy/HDiffPatch/**/*.h' | ||||||
|   end |   end | ||||||
|  |  | ||||||
|  |   if is_expo_project | ||||||
|  |     s.subspec 'Expo' do |ss| | ||||||
|  |       ss.source_files = 'ios/Expo/**/*.{h,m,mm,swift}' | ||||||
|  |     end | ||||||
|  |   end | ||||||
|  |  | ||||||
|   if defined?(install_modules_dependencies()) != nil |   if defined?(install_modules_dependencies()) != nil | ||||||
|     install_modules_dependencies(s); |     install_modules_dependencies(s); | ||||||
|   else |   else | ||||||
| @@ -60,7 +80,6 @@ Pod::Spec.new do |s| | |||||||
|           "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"", |           "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"", | ||||||
|           "CLANG_CXX_LANGUAGE_STANDARD" => "c++17" |           "CLANG_CXX_LANGUAGE_STANDARD" => "c++17" | ||||||
|       } |       } | ||||||
|  |  | ||||||
|       s.dependency "React-Codegen" |       s.dependency "React-Codegen" | ||||||
|       s.dependency "RCT-Folly" |       s.dependency "RCT-Folly" | ||||||
|       s.dependency "RCTRequired" |       s.dependency "RCTRequired" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 波仔糕
					波仔糕