Skip to content

Commit

Permalink
feat: support new arch android (#29)
Browse files Browse the repository at this point in the history
* fix: turbo spec

* fix: builder bob

* fix: spec

* feat: remove alreay zip

* fix: builder bob spawn error

* fix: ios

* feat: zipUrl not nullable

* fix: android studio gradle

* fix: reload

* fix: lint

* fix: module

* feat: using context based

* fix: singleton

* chore: pnpm bump

* fix(android): builde

* fix: android studio

* refactor: restart

* chore: modules

* refactor: some

* refactor: kt

* fix: new arch

* fix: update

* feat: progress store

* chore: biome

* fix: v0.71.19

* fix: arch separate

* fix: update

* fix: new arch

* fix: test
  • Loading branch information
gronxb authored Nov 26, 2024
1 parent c17060e commit 0b69aaf
Show file tree
Hide file tree
Showing 31 changed files with 1,474 additions and 1,032 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
# XDE
.expo/

# VSCode
.vscode/
jsconfig.json

# Xcode
Expand Down Expand Up @@ -89,4 +87,6 @@ docs/.vitepress/cache
.nx/cache
.nx/workspace-data

build.zip
build.zip

generated/
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"editor.defaultFormatter": "biomejs.biome",
"editor.codeActionsOnSave": {
"quickfix.biome": "explicit",
"source.organizeImports.biome": "explicit"
}
}
43 changes: 36 additions & 7 deletions examples/v0.71.19/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @format
*/

import { HotUpdater } from "@hot-updater/react-native";
import { HotUpdater, useHotUpdaterStore } from "@hot-updater/react-native";
import type React from "react";
import { useEffect, useState } from "react";
import { Button, Image, SafeAreaView, Text } from "react-native";
Expand All @@ -14,16 +14,34 @@ HotUpdater.init({
source: "https://gronxb.s3.ap-northeast-2.amazonaws.com/update.json",
});

function extractTimestampFromUUIDv7(uuid: string) {
const timestampHex = uuid.split("-").join("").slice(0, 12);

const timestamp = Number.parseInt(timestampHex, 16);

return timestamp;
}

function App(): React.JSX.Element {
const [version, setVersion] = useState<string | null>(null);
const [bundleId, setBundleId] = useState<string | null>(null);

const { progress } = useHotUpdaterStore();

useEffect(() => {
const version = HotUpdater.getBundleId();
setVersion(version);
const bundleId = HotUpdater.getBundleId();
setBundleId(bundleId);
}, []);

// @ts-expect-error
const isTurboModuleEnabled = global.__turboModuleProxy != null;

return (
<SafeAreaView>
<Text>Progress: {Math.round(progress * 100)}%</Text>
<Text>Babel {HotUpdater.HOT_UPDATER_BUNDLE_ID}</Text>
<Text>
Babel {extractTimestampFromUUIDv7(HotUpdater.HOT_UPDATER_BUNDLE_ID)}
</Text>
<Text
style={{
marginVertical: 20,
Expand All @@ -43,16 +61,27 @@ function App(): React.JSX.Element {
textAlign: "center",
}}
>
BundleId: {version}
BundleId: {bundleId}
</Text>

<Text
style={{
marginVertical: 20,
fontSize: 20,
fontWeight: "bold",
textAlign: "center",
}}
>
isTurboModuleEnabled: {isTurboModuleEnabled ? "true" : "false"}
</Text>

<Image
style={{
width: 100,
height: 100,
}}
// source={require("./src/logo.png")}
source={require("./src/test/_image.png")}
source={require("./src/logo.png")}
// source={require("./src/test/_image.png")}
/>

<Button title="Reload" onPress={() => HotUpdater.reload()} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
return packages;
}

Expand All @@ -36,7 +35,7 @@ protected String getJSMainModuleName() {

@Override
protected String getJSBundleFile() {
return HotUpdater.Companion.getJSBundleFile();
return HotUpdater.Companion.getJSBundleFile(this.getApplication().getApplicationContext());
}

@Override
Expand All @@ -59,7 +58,6 @@ public ReactNativeHost getReactNativeHost() {
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
HotUpdater.Companion.init(this, getReactNativeHost());

if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// If you opted-in for the New Architecture, we load the native entry point for this app.
Expand Down
3 changes: 2 additions & 1 deletion examples/v0.71.19/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
rootProject.name = 'HotUpdaterExample'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
includeBuild('../node_modules/react-native-gradle-plugin')
includeBuild(file('../node_modules/react-native-gradle-plugin').toPath().toRealPath().toAbsolutePath().toString())

1 change: 1 addition & 0 deletions examples/v0.71.19/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"jest": "^29.2.1",
"metro-react-native-babel-preset": "0.73.10",
"prettier": "^2.4.1",
"react-native-gradle-plugin": "^0.71.19",
"react-test-renderer": "18.2.0",
"typescript": "4.8.4"
},
Expand Down
42 changes: 36 additions & 6 deletions examples/v0.74.1/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @format
*/

import { HotUpdater } from "@hot-updater/react-native";
import { HotUpdater, useHotUpdaterStore } from "@hot-updater/react-native";
import type React from "react";
import { useEffect, useState } from "react";
import { Button, Image, SafeAreaView, Text } from "react-native";
Expand All @@ -14,16 +14,34 @@ HotUpdater.init({
source: "https://gronxb.s3.ap-northeast-2.amazonaws.com/update.json",
});

function extractTimestampFromUUIDv7(uuid: string) {
const timestampHex = uuid.split("-").join("").slice(0, 12);

const timestamp = Number.parseInt(timestampHex, 16);

return timestamp;
}

function App(): React.JSX.Element {
const [version, setVersion] = useState<string | null>(null);
const [bundleId, setBundleId] = useState<string | null>(null);

const { progress } = useHotUpdaterStore();

useEffect(() => {
const version = HotUpdater.getBundleId();
setVersion(version);
const bundleId = HotUpdater.getBundleId();
setBundleId(bundleId);
}, []);

// @ts-expect-error
const isTurboModuleEnabled = global.__turboModuleProxy != null;

return (
<SafeAreaView>
<Text>Progress: {Math.round(progress * 100)}%</Text>
<Text>Babel {HotUpdater.HOT_UPDATER_BUNDLE_ID}</Text>
<Text>
Babel {extractTimestampFromUUIDv7(HotUpdater.HOT_UPDATER_BUNDLE_ID)}
</Text>
<Text
style={{
marginVertical: 20,
Expand All @@ -43,15 +61,27 @@ function App(): React.JSX.Element {
textAlign: "center",
}}
>
BundleId: {version}
BundleId: {bundleId}
</Text>

<Text
style={{
marginVertical: 20,
fontSize: 20,
fontWeight: "bold",
textAlign: "center",
}}
>
isTurboModuleEnabled: {isTurboModuleEnabled ? "true" : "false"}
</Text>

<Image
style={{
width: 100,
height: 100,
}}
source={require("./src/test/_image.png")}
source={require("./src/logo.png")}
// source={require("./src/test/_image.png")}
/>

<Button title="Reload" onPress={() => HotUpdater.reload()} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
import com.facebook.react.defaults.DefaultReactNativeHost
import com.facebook.soloader.SoLoader
import com.hotupdater.HotUpdater
import android.util.Log

class MainApplication : Application(), ReactApplication {

Expand All @@ -30,8 +31,11 @@ class MainApplication : Application(), ReactApplication {
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED


override fun getJSBundleFile(): String? {
return HotUpdater.getJSBundleFile() ?: super.getJSBundleFile()
// This field
Log.d("HotUpdater", "getJSBundleFile: ${HotUpdater.getJSBundleFile(applicationContext)}")
return HotUpdater.getJSBundleFile(applicationContext)
}
}

Expand All @@ -42,7 +46,6 @@ class MainApplication : Application(), ReactApplication {
super.onCreate()

SoLoader.init(this, false)
HotUpdater.init(applicationContext, reactNativeHost)
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// If you opted-in for the New Architecture, we load the native entry point for this app.
load()
Expand Down
31 changes: 24 additions & 7 deletions examples/v0.76.1-new-arch/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @format
*/

import { HotUpdater } from "@hot-updater/react-native";
import { HotUpdater, useHotUpdaterStore } from "@hot-updater/react-native";
import type React from "react";
import { useEffect, useState } from "react";
import { Button, Image, SafeAreaView, Text } from "react-native";
Expand All @@ -23,15 +23,21 @@ function extractTimestampFromUUIDv7(uuid: string) {
}

function App(): React.JSX.Element {
const [version, setVersion] = useState<string | null>(null);
const [bundleId, setBundleId] = useState<string | null>(null);

const { progress } = useHotUpdaterStore();

useEffect(() => {
const version = HotUpdater.getBundleId();
setVersion(version);
const bundleId = HotUpdater.getBundleId();
setBundleId(bundleId);
}, []);

// @ts-expect-error
const isTurboModuleEnabled = global.__turboModuleProxy != null;

return (
<SafeAreaView>
<Text>Progress: {Math.round(progress * 100)}%</Text>
<Text>Babel {HotUpdater.HOT_UPDATER_BUNDLE_ID}</Text>
<Text>
Babel {extractTimestampFromUUIDv7(HotUpdater.HOT_UPDATER_BUNDLE_ID)}
Expand All @@ -55,16 +61,27 @@ function App(): React.JSX.Element {
textAlign: "center",
}}
>
BundleId: {version}
BundleId: {bundleId}
</Text>

<Text
style={{
marginVertical: 20,
fontSize: 20,
fontWeight: "bold",
textAlign: "center",
}}
>
isTurboModuleEnabled: {isTurboModuleEnabled ? "true" : "false"}
</Text>

<Image
style={{
width: 100,
height: 100,
}}
// source={require("./src/logo.png")}
source={require("./src/test/_image.png")}
source={require("./src/logo.png")}
// source={require("./src/test/_image.png")}
/>

<Button title="Reload" onPress={() => HotUpdater.reload()} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hotupdaterexample

import android.app.Application
import android.util.Log
import com.facebook.react.PackageList
import com.facebook.react.ReactApplication
import com.facebook.react.ReactHost
Expand Down Expand Up @@ -33,17 +34,17 @@ class MainApplication :

override fun getJSBundleFile(): String? {
// This field
return HotUpdater.getJSBundleFile() ?: super.getJSBundleFile()
Log.d("HotUpdater", "getJSBundleFile: ${HotUpdater.getJSBundleFile(applicationContext)}")
return HotUpdater.getJSBundleFile(applicationContext)
}
}

override val reactHost: ReactHost
get() = getDefaultReactHost(applicationContext, reactNativeHost)
get() = getDefaultReactHost(applicationContext, reactNativeHost)

override fun onCreate() {
super.onCreate()
SoLoader.init(this, OpenSourceMergedSoMapping)
HotUpdater.init(applicationContext, reactNativeHost)

if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// If you opted-in for the New Architecture, we load the native entry point for this app.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"publish:rc": "nx release publish --tag rc"
},
"devDependencies": {
"@biomejs/biome": "1.9.3",
"@biomejs/biome": "^1.9.4",
"@nx/js": "^20.0.6",
"@swc-node/register": "^1.10.9",
"@swc/core": "^1.7.40",
Expand All @@ -41,5 +41,5 @@
"@hot-updater/react": "workspace:*"
}
},
"packageManager": "pnpm@9.12.3"
"packageManager": "pnpm@9.14.2"
}
2 changes: 1 addition & 1 deletion packages/console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"test:type": "tsc --noEmit"
},
"devDependencies": {
"@biomejs/biome": "^1.9.3",
"@biomejs/biome": "^1.9.4",
"@hono/valibot-validator": "^0.4.1",
"@kobalte/core": "^0.13.7",
"@rsbuild/core": "^1.0.18",
Expand Down
1 change: 1 addition & 0 deletions packages/hot-updater/src/utils/createZip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import JSZip from "jszip";

export const createZip = async (dirPath: string, filename: string) => {
const zip = new JSZip();
await fs.rm(path.join(dirPath, filename), { force: true });

async function addFiles(dir: string, zipFolder: JSZip) {
const files = await fs.readdir(dir);
Expand Down
Loading

0 comments on commit 0b69aaf

Please sign in to comment.