peachsim 0.1.2300 → 0.1.2302
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/commands/control.ts +1 -0
- package/cli/commands/inspect.ts +2 -1
- package/cli/commands/shell-url.ts +5 -0
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +1 -1
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +1 -1
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +1 -1
- package/dist-lib/bundle-channel.cjs +677 -355
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +1 -1
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +1 -1
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +1 -1
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/config.mjs +1 -1
- package/dist-lib/detox/index.cjs +3 -2
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/expo-swift-bundle.cjs +628 -306
- package/dist-lib/expo-swift-metadata.cjs +1 -1
- package/dist-lib/expo-swift-metadata.mjs +1 -1
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +2889 -354
- package/dist-lib/host/fetch-proxy-handler.cjs +6 -6
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +14 -9
- package/dist-lib/jump-to-source-babel.cjs +1 -1
- package/dist-lib/jump-to-source-native.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +1 -1
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +1 -1
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +1 -1
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +1 -1
- package/dist-lib/metro.cjs +13 -9
- package/dist-lib/native-app-identity-project.cjs +9 -5
- package/dist-lib/native-app-identity-project.mjs +9 -5
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +1 -1
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +1 -1
- package/dist-lib/pdfium-raster.cjs +1 -1
- package/dist-lib/pdfium-raster.mjs +1 -1
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +1 -1
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/public-origins-lib-esm.json +24 -24
- package/dist-lib/public-origins-lib.json +56 -53
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +1 -1
- package/dist-lib/reap-browser.cjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
- package/dist-lib/sdk.cjs +2 -1
- package/dist-lib/sdk.mjs +2 -1
- package/dist-lib/skills.cjs +788 -415
- package/dist-lib/swift-compile.cjs +15 -7
- package/dist-lib/swift-compile.mjs +15 -7
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +1 -1
- package/dist-lib/swift-submit.cjs +1 -1
- package/dist-lib/swift-submit.mjs +1 -1
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +23 -11
- package/dist-lib/vite.cjs +6 -6
- package/dist-lib/worklet-executable.cjs +1 -1
- package/dist-lib/worklet-executable.mjs +1 -1
- package/dist-types/packages/peach-engine/src/components/native-ui/webview-frame-bridge.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/engine/font-config.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/engine/scene-table.d.ts +2 -0
- package/dist-types/packages/peach-engine/src/render-worker/activitykit-activityContract.d.ts +17 -0
- package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +5 -0
- package/dist-types/packages/peach-engine/src/render-worker/native-ui-protocol.d.ts +4 -0
- package/dist-types/packages/peach-engine/src/render-worker/native-widgetContract.d.ts +3 -1
- package/dist-types/packages/peach-kit/src/capabilities.d.ts +4 -0
- package/java-platform/licenses/fdlibm.txt +3 -0
- package/kotlin/sdk.tar.gz +0 -0
- package/package.json +1 -1
- package/runtime-companion.json +1 -1
- package/src/expo-discovery-cache.ts +6 -6
- package/src/expo-native-workspace.ts +85 -37
- package/src/expo-swift-host.ts +19 -4
- package/src/host/bridge-host.ts +9 -0
- package/src/launchMetadataContract.ts +1 -0
- package/src/one-sdk-preparation.ts +61 -5
- package/src/swift-guest-compile.ts +19 -3
- package/src/swift-guest-source-plan.ts +7 -2
- package/src/swiftContract.ts +3 -0
- package/src/turbo-compile.ts +60 -4
- package/src/turbo-source.ts +239 -35
- package/src/widget-extension-bundle.ts +48 -0
- package/src/xcode-project.ts +22 -3
package/src/turbo-source.ts
CHANGED
|
@@ -112,6 +112,14 @@ export interface TurboSourceCollection {
|
|
|
112
112
|
externalPodSources: { moduleName: string; file: string }[]
|
|
113
113
|
/** the Swift targets compiled from react-native's own renderer pods */
|
|
114
114
|
rendererSwiftTargets: string[]
|
|
115
|
+
/** the codegen component names whose views the host mounts */
|
|
116
|
+
fabricComponents: string[]
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// a codegen component and the class RCTThirdPartyComponentsProvider maps it to
|
|
120
|
+
interface FabricComponent {
|
|
121
|
+
name: string
|
|
122
|
+
className: string
|
|
115
123
|
}
|
|
116
124
|
|
|
117
125
|
export const TURBO_CORE_TARGET = 'TurboCore'
|
|
@@ -1166,6 +1174,7 @@ export async function collectTurboSources(options: {
|
|
|
1166
1174
|
sources: [],
|
|
1167
1175
|
externalPodSources: [],
|
|
1168
1176
|
rendererSwiftTargets: [],
|
|
1177
|
+
fabricComponents: [],
|
|
1169
1178
|
}
|
|
1170
1179
|
const sharedLibrary = [...(options.installedPods?.values() ?? [])].find(
|
|
1171
1180
|
(pod) => pod.sharedLibrary,
|
|
@@ -1718,6 +1727,10 @@ export async function collectTurboSources(options: {
|
|
|
1718
1727
|
|
|
1719
1728
|
let objc = Boolean(options.reactNativeProvider)
|
|
1720
1729
|
let fabric = Boolean(options.reactNativeProvider)
|
|
1730
|
+
// the packages whose own Fabric components compile here
|
|
1731
|
+
const fabricPackages = new Set<string>()
|
|
1732
|
+
const fabricViews: FabricComponent[] = []
|
|
1733
|
+
let fabricTarget: { targetName: string; label: string; root: string } | null = null
|
|
1721
1734
|
let legacyBridge = false
|
|
1722
1735
|
let hermesHeaders: string | null = null
|
|
1723
1736
|
const objcClasses = new Set<string>()
|
|
@@ -1752,7 +1765,11 @@ export async function collectTurboSources(options: {
|
|
|
1752
1765
|
{ tool: 'cxx', flags: pod.installed.preprocessorFlags.cxx },
|
|
1753
1766
|
]
|
|
1754
1767
|
const root = pod.root
|
|
1755
|
-
|
|
1768
|
+
if (fabricComponents(provider.root)) {
|
|
1769
|
+
fabric = true
|
|
1770
|
+
fabricPackages.add(provider.name)
|
|
1771
|
+
fabricTarget ??= { targetName, label, root: provider.root }
|
|
1772
|
+
}
|
|
1756
1773
|
if (pod.installed?.library) {
|
|
1757
1774
|
result.libraries ??= {}
|
|
1758
1775
|
result.libraries[targetName] = fs
|
|
@@ -2066,6 +2083,20 @@ export async function collectTurboSources(options: {
|
|
|
2066
2083
|
const owned = new Set<string>()
|
|
2067
2084
|
walkFiles(generated, '', owned)
|
|
2068
2085
|
const spec = codegenConfig.name
|
|
2086
|
+
let definedComponentNames: Set<string> | undefined
|
|
2087
|
+
const getDefinedComponentNames = () => {
|
|
2088
|
+
if (definedComponentNames) return definedComponentNames
|
|
2089
|
+
definedComponentNames = new Set()
|
|
2090
|
+
const pattern =
|
|
2091
|
+
/\b(?:const\s+char|char\s+const)\s+(\w+ComponentName)\s*\[\s*\]\s*=/g
|
|
2092
|
+
for (const sourceFile of sources) {
|
|
2093
|
+
const text = readPackageFile(root, path.join(root, sourceFile), Infinity)
|
|
2094
|
+
.toString('utf8')
|
|
2095
|
+
.replace(/\/\/[^\n]*/g, '')
|
|
2096
|
+
for (const match of text.matchAll(pattern)) definedComponentNames.add(match[1]!)
|
|
2097
|
+
}
|
|
2098
|
+
return definedComponentNames
|
|
2099
|
+
}
|
|
2069
2100
|
for (const file of [...owned].sort()) {
|
|
2070
2101
|
const base = path.posix.basename(file)
|
|
2071
2102
|
// the Objective-C spec classes only an Objective-C module reaches
|
|
@@ -2092,7 +2123,35 @@ export async function collectTurboSources(options: {
|
|
|
2092
2123
|
relative: file,
|
|
2093
2124
|
},
|
|
2094
2125
|
)
|
|
2095
|
-
else
|
|
2126
|
+
else {
|
|
2127
|
+
if (component && base === 'ShadowNodes.cpp') {
|
|
2128
|
+
const defined = getDefinedComponentNames()
|
|
2129
|
+
if (defined.size) {
|
|
2130
|
+
const source = readPackageFile(
|
|
2131
|
+
generated,
|
|
2132
|
+
path.join(generated, file),
|
|
2133
|
+
Infinity,
|
|
2134
|
+
).toString('utf8')
|
|
2135
|
+
const filtered = source.replace(
|
|
2136
|
+
/^[ \t]*(?:extern[ \t]+)?(?:const[ \t]+char|char[ \t]+const)[ \t]+(\w+ComponentName)[ \t]*\[[ \t]*\][ \t]*=[^;]*;[ \t]*\r?\n?/gm,
|
|
2137
|
+
(line, name: string) => (defined.has(name) ? '' : line),
|
|
2138
|
+
)
|
|
2139
|
+
if (filtered !== source) {
|
|
2140
|
+
// a pod's own Fabric node sources can already define ComponentName[], clashing with codegen's ShadowNodes.cpp
|
|
2141
|
+
if (
|
|
2142
|
+
!/\b(?:const\s+char|char\s+const)\s+\w+ComponentName\s*\[\s*\]\s*=/.test(
|
|
2143
|
+
filtered,
|
|
2144
|
+
)
|
|
2145
|
+
)
|
|
2146
|
+
continue
|
|
2147
|
+
const key = original(targetName, 'ReactCodegen', generated, file)
|
|
2148
|
+
result.files[key] = filtered
|
|
2149
|
+
continue
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
original(targetName, 'ReactCodegen', generated, file)
|
|
2154
|
+
}
|
|
2096
2155
|
}
|
|
2097
2156
|
}
|
|
2098
2157
|
for (const file of sources) original(targetName, label, root, file)
|
|
@@ -2165,7 +2224,7 @@ export async function collectTurboSources(options: {
|
|
|
2165
2224
|
// React module defines itself
|
|
2166
2225
|
add(
|
|
2167
2226
|
`${core}/${TURBO_CORE_PUBLIC_HEADERS}/${TURBO_ENTRY_HEADER}`,
|
|
2168
|
-
'#pragma once\nextern "C" void peachTurboInitialize();\n',
|
|
2227
|
+
'#pragma once\nextern "C" void peachTurboInitialize();\n// the +1 Fabric component view a root of the process shows, in an app with one\nextern "C" void *peach_fabric_view_content(int tag);\n',
|
|
2169
2228
|
)
|
|
2170
2229
|
add(
|
|
2171
2230
|
`${core}/${TURBO_CORE_PUBLIC_HEADERS}/module.modulemap`,
|
|
@@ -2319,6 +2378,26 @@ export async function collectTurboSources(options: {
|
|
|
2319
2378
|
original(TURBO_CORE_TARGET, 'ReactCodegen', generated, 'RCTModuleProviders.h'),
|
|
2320
2379
|
)
|
|
2321
2380
|
}
|
|
2381
|
+
// the app's components as its RCTThirdPartyComponentsProvider maps them,
|
|
2382
|
+
// less those of packages Peach answers itself, whose classes are not linked
|
|
2383
|
+
const thirdParty = path.join(generated, 'RCTThirdPartyComponentsProvider.mm')
|
|
2384
|
+
if (fabricPackages.size > 0 && fs.existsSync(thirdParty))
|
|
2385
|
+
for (const [, name, className, owner] of fs
|
|
2386
|
+
.readFileSync(thirdParty, 'utf8')
|
|
2387
|
+
.matchAll(/@"([^"]+)": NSClassFromString\(@"([^"]+)"\), \/\/ (\S+)/g))
|
|
2388
|
+
if (fabricPackages.has(owner!))
|
|
2389
|
+
fabricViews.push({ name: name!, className: className! })
|
|
2390
|
+
// the host compiles with the first Fabric package's own settings, which
|
|
2391
|
+
// reach the React Fabric headers its component views include
|
|
2392
|
+
if (fabricViews.length > 0 && fabricTarget) {
|
|
2393
|
+
result.fabricComponents = fabricViews.map(({ name }) => name)
|
|
2394
|
+
const unit = `${targetPath(fabricTarget.targetName)}/PeachFabricHost.mm`
|
|
2395
|
+
add(unit, fabricHostSource(fabricViews))
|
|
2396
|
+
scanText(
|
|
2397
|
+
{ key: unit, ...fabricTarget, relative: 'PeachFabricHost.mm' },
|
|
2398
|
+
result.files[unit]!,
|
|
2399
|
+
)
|
|
2400
|
+
}
|
|
2322
2401
|
}
|
|
2323
2402
|
if (fabric || legacyBridge) {
|
|
2324
2403
|
// React-Core's own compiler_flags select the Hermes executor factory,
|
|
@@ -2723,38 +2802,6 @@ void dispatchToJSThread(dispatch_block_t block) {
|
|
|
2723
2802
|
}
|
|
2724
2803
|
} // namespace
|
|
2725
2804
|
|
|
2726
|
-
static CGFloat peachScreenBrightness = 0.5;
|
|
2727
|
-
|
|
2728
|
-
@implementation UIScreen (PeachTurboRuntime)
|
|
2729
|
-
+ (UIScreen *)mainScreen {
|
|
2730
|
-
static UIScreen *screen = nil;
|
|
2731
|
-
if (!screen) screen = [[UIScreen alloc] init];
|
|
2732
|
-
return screen;
|
|
2733
|
-
}
|
|
2734
|
-
- (CGFloat)brightness {
|
|
2735
|
-
return peachScreenBrightness;
|
|
2736
|
-
}
|
|
2737
|
-
- (void)setBrightness:(CGFloat)value {
|
|
2738
|
-
peachScreenBrightness = value;
|
|
2739
|
-
}
|
|
2740
|
-
@end
|
|
2741
|
-
|
|
2742
|
-
static BOOL peachIdleTimerDisabled = NO;
|
|
2743
|
-
|
|
2744
|
-
@implementation UIApplication (PeachTurboRuntime)
|
|
2745
|
-
+ (UIApplication *)sharedApplication {
|
|
2746
|
-
static UIApplication *app = nil;
|
|
2747
|
-
if (!app) app = [[UIApplication alloc] init];
|
|
2748
|
-
return app;
|
|
2749
|
-
}
|
|
2750
|
-
- (BOOL)isIdleTimerDisabled {
|
|
2751
|
-
return peachIdleTimerDisabled;
|
|
2752
|
-
}
|
|
2753
|
-
- (void)setIdleTimerDisabled:(BOOL)disabled {
|
|
2754
|
-
peachIdleTimerDisabled = disabled;
|
|
2755
|
-
}
|
|
2756
|
-
@end
|
|
2757
|
-
|
|
2758
2805
|
// React Native's own modules register before any provider's, and RCTBridge.mm
|
|
2759
2806
|
// creates the registry's queue in the first RCTRegisterModule. the engine
|
|
2760
2807
|
// supplies those modules, so a process whose providers register none (codegen
|
|
@@ -2875,6 +2922,12 @@ ${
|
|
|
2875
2922
|
|
|
2876
2923
|
@end
|
|
2877
2924
|
|
|
2925
|
+
// an app's Fabric component views, which its own Fabric host defines
|
|
2926
|
+
extern "C" void peachInstallFabricViews(facebook::jsi::Runtime &runtime) __attribute__((weak));
|
|
2927
|
+
|
|
2928
|
+
// UIKitCore: the key window and root view controller an app delegate makes at launch
|
|
2929
|
+
extern "C" void PeachLaunchReactNativeWindow(void);
|
|
2930
|
+
|
|
2878
2931
|
extern "C" void peachTurboInitialize() {
|
|
2879
2932
|
objc_create_block_classes_as_subclasses_of([NSObject class]);
|
|
2880
2933
|
if (Class blockClass = NSClassFromString(@"_NSBlock")) {
|
|
@@ -2888,6 +2941,7 @@ extern "C" void peachTurboInitialize() {
|
|
|
2888
2941
|
static_cast<uint32_t *>((__bridge void *)mainQueueClass)[4] &= ~2048u;
|
|
2889
2942
|
*reinterpret_cast<void **>(&_dispatch_main_q) = (__bridge void *)mainQueueClass;
|
|
2890
2943
|
}
|
|
2944
|
+
PeachLaunchReactNativeWindow();
|
|
2891
2945
|
auto& runtime = peach::jsi_runtime::create(
|
|
2892
2946
|
[] { invoker->drain(); },
|
|
2893
2947
|
[] {
|
|
@@ -2952,6 +3006,7 @@ ${
|
|
|
2952
3006
|
}];
|
|
2953
3007
|
[decorator.moduleRegistry setTurboModuleRegistry:manager];
|
|
2954
3008
|
[manager installJSBindings:runtime];
|
|
3009
|
+
if (peachInstallFabricViews) peachInstallFabricViews(runtime);
|
|
2955
3010
|
}
|
|
2956
3011
|
|
|
2957
3012
|
// the screenshot the device took, as UIKit posts it to every observer in the
|
|
@@ -2997,3 +3052,152 @@ ${moduleProviders ? ' [found addObjectsFromArray:RCTModuleProviders.moduleProvi
|
|
|
2997
3052
|
}
|
|
2998
3053
|
`
|
|
2999
3054
|
}
|
|
3055
|
+
|
|
3056
|
+
const FABRIC_HOST_INCLUDES = `#import <Foundation/Foundation.h>
|
|
3057
|
+
#import <React/RCTComponentViewFactory.h>
|
|
3058
|
+
#import <React/RCTComponentViewProtocol.h>
|
|
3059
|
+
#import <React/RCTComponentViewRegistry.h>
|
|
3060
|
+
#include <react/renderer/componentregistry/ComponentDescriptorRegistry.h>
|
|
3061
|
+
#include <react/renderer/core/LayoutMetrics.h>
|
|
3062
|
+
#include <react/renderer/core/PropsParserContext.h>
|
|
3063
|
+
#include <react/renderer/core/RawProps.h>
|
|
3064
|
+
#include <react/utils/ContextContainer.h>
|
|
3065
|
+
#include <cstdio>
|
|
3066
|
+
#include <cstdlib>
|
|
3067
|
+
#include <unordered_map>
|
|
3068
|
+
#include <jsi/jsi.h>
|
|
3069
|
+
|
|
3070
|
+
using namespace facebook;
|
|
3071
|
+
`
|
|
3072
|
+
|
|
3073
|
+
// the app's codegen components mounted as React Native's RCTMountingManager
|
|
3074
|
+
// mounts them (RCTPerformMountInstructions): the component view factory with
|
|
3075
|
+
// the app's third-party components, one registry dequeuing and recycling
|
|
3076
|
+
// views, and props each component's descriptor clones from the props React
|
|
3077
|
+
// passes. the engine lays the view out and paints its style; the view is the
|
|
3078
|
+
// content of a root of this process.
|
|
3079
|
+
function fabricHostSource(views: readonly FabricComponent[]): string {
|
|
3080
|
+
const entries = views
|
|
3081
|
+
.map(
|
|
3082
|
+
({ name, className }) =>
|
|
3083
|
+
`@${JSON.stringify(name)}: NSClassFromString(@${JSON.stringify(className)})`,
|
|
3084
|
+
)
|
|
3085
|
+
.join(', ')
|
|
3086
|
+
return `${FABRIC_HOST_INCLUDES}
|
|
3087
|
+
@interface PeachFabricComponents : NSObject <RCTComponentViewFactoryComponentProvider>
|
|
3088
|
+
@end
|
|
3089
|
+
|
|
3090
|
+
@implementation PeachFabricComponents
|
|
3091
|
+
- (NSDictionary<NSString *, Class<RCTComponentViewProtocol>> *)thirdPartyFabricComponents
|
|
3092
|
+
{
|
|
3093
|
+
return @{${entries}};
|
|
3094
|
+
}
|
|
3095
|
+
@end
|
|
3096
|
+
|
|
3097
|
+
namespace {
|
|
3098
|
+
struct PeachFabricView {
|
|
3099
|
+
react::ComponentHandle handle;
|
|
3100
|
+
const react::ComponentDescriptor *descriptor;
|
|
3101
|
+
react::Props::Shared props;
|
|
3102
|
+
react::LayoutMetrics layoutMetrics;
|
|
3103
|
+
};
|
|
3104
|
+
PeachFabricComponents *fabricComponents;
|
|
3105
|
+
RCTComponentViewRegistry *fabricRegistry;
|
|
3106
|
+
std::shared_ptr<const react::ContextContainer> fabricContext;
|
|
3107
|
+
react::ComponentDescriptorRegistry::Shared fabricDescriptors;
|
|
3108
|
+
std::unordered_map<int, PeachFabricView> fabricViews;
|
|
3109
|
+
int nextFabricView = 1;
|
|
3110
|
+
std::string fabricNames = ${JSON.stringify(views.map(({ name }) => name).join('\n'))};
|
|
3111
|
+
|
|
3112
|
+
PeachFabricView &fabricView(int tag) {
|
|
3113
|
+
auto found = fabricViews.find(tag);
|
|
3114
|
+
if (found == fabricViews.end()) {
|
|
3115
|
+
std::fprintf(stderr, "no mounted Fabric view %d\\n", tag);
|
|
3116
|
+
std::abort();
|
|
3117
|
+
}
|
|
3118
|
+
return found->second;
|
|
3119
|
+
}
|
|
3120
|
+
|
|
3121
|
+
react::Props::Shared fabricCloneProps(jsi::Runtime &rt, const PeachFabricView &view, const jsi::Value &props) {
|
|
3122
|
+
react::PropsParserContext context{-1, *fabricContext};
|
|
3123
|
+
return view.descriptor->cloneProps(context, view.props, react::RawProps(rt, props));
|
|
3124
|
+
}
|
|
3125
|
+
|
|
3126
|
+
} // namespace
|
|
3127
|
+
|
|
3128
|
+
extern "C" void peachInstallFabricViews(jsi::Runtime &rt) {
|
|
3129
|
+
fabricComponents = [PeachFabricComponents new];
|
|
3130
|
+
RCTComponentViewFactory *factory = [RCTComponentViewFactory currentComponentViewFactory];
|
|
3131
|
+
factory.thirdPartyFabricComponentsProvider = fabricComponents;
|
|
3132
|
+
fabricRegistry = [RCTComponentViewRegistry new];
|
|
3133
|
+
fabricContext = std::make_shared<const react::ContextContainer>();
|
|
3134
|
+
react::ComponentDescriptorParameters parameters{{}, fabricContext, nullptr};
|
|
3135
|
+
fabricDescriptors = [factory createComponentDescriptorRegistryWithParameters:parameters];
|
|
3136
|
+
auto views = jsi::Object(rt);
|
|
3137
|
+
auto method = [&](const char *name, unsigned count, jsi::HostFunctionType body) {
|
|
3138
|
+
views.setProperty(rt, name, jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, name), count, std::move(body)));
|
|
3139
|
+
};
|
|
3140
|
+
// Create then Insert: the first props, no event emitter or state, and the
|
|
3141
|
+
// layout the view has before the engine measures it
|
|
3142
|
+
method("create", 2, [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, size_t) -> jsi::Value {
|
|
3143
|
+
const auto &descriptor = fabricDescriptors->at(args[0].asString(rt).utf8(rt));
|
|
3144
|
+
int tag = nextFabricView++;
|
|
3145
|
+
auto &view = fabricViews.emplace(tag, PeachFabricView{descriptor.getComponentHandle(), &descriptor, nullptr, {}}).first->second;
|
|
3146
|
+
view.props = fabricCloneProps(rt, view, args[1]);
|
|
3147
|
+
UIView<RCTComponentViewProtocol> *componentView =
|
|
3148
|
+
[fabricRegistry dequeueComponentViewWithComponentHandle:view.handle tag:tag].view;
|
|
3149
|
+
[componentView updateProps:view.props oldProps:nullptr];
|
|
3150
|
+
[componentView updateEventEmitter:nullptr];
|
|
3151
|
+
[componentView updateState:nullptr oldState:nullptr];
|
|
3152
|
+
[componentView updateLayoutMetrics:view.layoutMetrics oldLayoutMetrics:react::EmptyLayoutMetrics];
|
|
3153
|
+
[componentView finalizeUpdates:RNComponentViewUpdateMaskAll];
|
|
3154
|
+
return jsi::Value(tag);
|
|
3155
|
+
});
|
|
3156
|
+
// Update with the props React changed since the last commit
|
|
3157
|
+
method("update", 2, [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, size_t) -> jsi::Value {
|
|
3158
|
+
int tag = static_cast<int>(args[0].asNumber());
|
|
3159
|
+
auto &view = fabricView(tag);
|
|
3160
|
+
auto oldProps = view.props;
|
|
3161
|
+
view.props = fabricCloneProps(rt, view, args[1]);
|
|
3162
|
+
UIView<RCTComponentViewProtocol> *componentView = [fabricRegistry componentViewDescriptorWithTag:tag].view;
|
|
3163
|
+
[componentView updateProps:view.props oldProps:oldProps];
|
|
3164
|
+
[componentView finalizeUpdates:RNComponentViewUpdateMaskProps];
|
|
3165
|
+
return jsi::Value::undefined();
|
|
3166
|
+
});
|
|
3167
|
+
// Update with the size and scale the engine laid the view out at
|
|
3168
|
+
method("layout", 4, [](jsi::Runtime &, const jsi::Value &, const jsi::Value *args, size_t) -> jsi::Value {
|
|
3169
|
+
int tag = static_cast<int>(args[0].asNumber());
|
|
3170
|
+
auto &view = fabricView(tag);
|
|
3171
|
+
auto metrics = view.layoutMetrics;
|
|
3172
|
+
metrics.frame = react::Rect{{0, 0}, {static_cast<react::Float>(args[1].asNumber()), static_cast<react::Float>(args[2].asNumber())}};
|
|
3173
|
+
metrics.pointScaleFactor = static_cast<react::Float>(args[3].asNumber());
|
|
3174
|
+
if (metrics == view.layoutMetrics) return jsi::Value::undefined();
|
|
3175
|
+
UIView<RCTComponentViewProtocol> *componentView = [fabricRegistry componentViewDescriptorWithTag:tag].view;
|
|
3176
|
+
[componentView updateLayoutMetrics:metrics oldLayoutMetrics:view.layoutMetrics];
|
|
3177
|
+
view.layoutMetrics = metrics;
|
|
3178
|
+
[componentView finalizeUpdates:RNComponentViewUpdateMaskLayoutMetrics];
|
|
3179
|
+
return jsi::Value::undefined();
|
|
3180
|
+
});
|
|
3181
|
+
// Remove then Delete: the registry recycles the view
|
|
3182
|
+
method("drop", 1, [](jsi::Runtime &, const jsi::Value &, const jsi::Value *args, size_t) -> jsi::Value {
|
|
3183
|
+
int tag = static_cast<int>(args[0].asNumber());
|
|
3184
|
+
auto &view = fabricView(tag);
|
|
3185
|
+
RCTComponentViewDescriptor descriptor = [fabricRegistry componentViewDescriptorWithTag:tag];
|
|
3186
|
+
[descriptor.view removeFromSuperview];
|
|
3187
|
+
[fabricRegistry enqueueComponentViewWithComponentHandle:view.handle tag:tag componentViewDescriptor:descriptor];
|
|
3188
|
+
fabricViews.erase(tag);
|
|
3189
|
+
return jsi::Value::undefined();
|
|
3190
|
+
});
|
|
3191
|
+
rt.global().setProperty(rt, "peachFabricViews", std::move(views));
|
|
3192
|
+
}
|
|
3193
|
+
|
|
3194
|
+
extern "C" void *peach_fabric_view_content(int tag) {
|
|
3195
|
+
return (__bridge_retained void *)[fabricRegistry componentViewDescriptorWithTag:tag].view;
|
|
3196
|
+
}
|
|
3197
|
+
|
|
3198
|
+
// the component names the host registers as views, newline separated
|
|
3199
|
+
extern "C" __attribute__((export_name("peach_fabric_component_names"))) const char *peachFabricComponentNames() {
|
|
3200
|
+
return fabricNames.c_str();
|
|
3201
|
+
}
|
|
3202
|
+
`
|
|
3203
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { prepareNativeAppRoot } from './expo-native-workspace'
|
|
2
|
+
import { compiledModuleRequestHandler } from './nitro-bundle'
|
|
3
|
+
import { swiftDistributionRoot } from './swift-distribution'
|
|
4
|
+
import {
|
|
5
|
+
openXcodeProject,
|
|
6
|
+
prepareXcodeSwiftPackages,
|
|
7
|
+
swiftPackageMetadata,
|
|
8
|
+
} from './swift-host'
|
|
9
|
+
import { installedXcodeWorkspace, readXcodeExtensionTargets } from './xcode-project'
|
|
10
|
+
import type { SwiftEntryOptions } from './swiftContract'
|
|
11
|
+
|
|
12
|
+
export const WIDGET_EXTENSION_ROUTE = '/__peach/widget-extension'
|
|
13
|
+
|
|
14
|
+
// the app's WidgetKit extension target, compiled from the installed workspace
|
|
15
|
+
// with the pods its own Podfile target links, as Xcode builds the extension
|
|
16
|
+
// process that draws the app's widgets and live activities.
|
|
17
|
+
export async function compileWidgetExtension(
|
|
18
|
+
appRoot: string,
|
|
19
|
+
origin: string,
|
|
20
|
+
): Promise<{ metadata: SwiftEntryOptions } | null> {
|
|
21
|
+
const projectRoot = await prepareNativeAppRoot(appRoot)
|
|
22
|
+
const workspace = installedXcodeWorkspace(projectRoot)
|
|
23
|
+
if (!workspace) return null
|
|
24
|
+
const extensions = readXcodeExtensionTargets(workspace).filter(({ infoPlist }) => {
|
|
25
|
+
const extension = infoPlist.NSExtension
|
|
26
|
+
return (
|
|
27
|
+
typeof extension === 'object' &&
|
|
28
|
+
extension !== null &&
|
|
29
|
+
'NSExtensionPointIdentifier' in extension &&
|
|
30
|
+
extension.NSExtensionPointIdentifier === 'com.apple.widgetkit-extension'
|
|
31
|
+
)
|
|
32
|
+
})
|
|
33
|
+
if (extensions.length === 0) return null
|
|
34
|
+
if (extensions.length > 1)
|
|
35
|
+
throw new Error(
|
|
36
|
+
`${workspace}: more than one WidgetKit extension (${extensions.map(({ name }) => name).join(', ')}) is unmeasured`,
|
|
37
|
+
)
|
|
38
|
+
const { name } = extensions[0]!
|
|
39
|
+
const moduleRoot = await swiftDistributionRoot()
|
|
40
|
+
await prepareXcodeSwiftPackages(workspace, name, 'Release')
|
|
41
|
+
const root = openXcodeProject(workspace, name, moduleRoot, 'Release')
|
|
42
|
+
return { metadata: await swiftPackageMetadata(root, name, moduleRoot, origin) }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const handleWidgetExtensionRequest = compiledModuleRequestHandler(
|
|
46
|
+
'Widget extension',
|
|
47
|
+
(root, origin) => compileWidgetExtension(root, origin),
|
|
48
|
+
)
|
package/src/xcode-project.ts
CHANGED
|
@@ -225,6 +225,7 @@ export interface XcodeAppTarget extends XcodeModuleTarget {
|
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
const APPLICATION = 'com.apple.product-type.application'
|
|
228
|
+
const APP_EXTENSION = 'com.apple.product-type.app-extension'
|
|
228
229
|
const RESOURCE_BUNDLE = 'com.apple.product-type.bundle'
|
|
229
230
|
// the MACH_O_TYPE each product type builds with when no setting names one, from
|
|
230
231
|
// the product type specifications in Xcode's CoreBuildSystem plugin.
|
|
@@ -1589,7 +1590,7 @@ export function readXcodeExtensionTargets(input: string): {
|
|
|
1589
1590
|
}[] {
|
|
1590
1591
|
return workspaceProjects(fs.realpathSync.native(input)).projects.flatMap((project) =>
|
|
1591
1592
|
projectTargets(project).flatMap((ref) => {
|
|
1592
|
-
if (ref.target.productType !==
|
|
1593
|
+
if (ref.target.productType !== APP_EXTENSION) return []
|
|
1593
1594
|
const name = str(ref.target.name) ?? ref.id
|
|
1594
1595
|
const { get, keys, xcconfigs } = targetSettings(
|
|
1595
1596
|
ref,
|
|
@@ -1907,7 +1908,14 @@ export function readXcodeAppTarget(
|
|
|
1907
1908
|
options.installedPods,
|
|
1908
1909
|
)
|
|
1909
1910
|
const allTargets = projects.flatMap(projectTargets)
|
|
1910
|
-
|
|
1911
|
+
// an extension runs as its own process: named, it builds as the compiled unit
|
|
1912
|
+
const appTargets = allTargets.filter(
|
|
1913
|
+
(ref) =>
|
|
1914
|
+
isIosAppTarget(ref, options) ||
|
|
1915
|
+
(targetName !== undefined &&
|
|
1916
|
+
ref.target.name === targetName &&
|
|
1917
|
+
ref.target.productType === APP_EXTENSION),
|
|
1918
|
+
)
|
|
1911
1919
|
const appTargetNames = appTargets.map((ref) => str(ref.target.name) ?? ref.id)
|
|
1912
1920
|
const container = path.basename(xcodeprojOrWorkspace)
|
|
1913
1921
|
const named = targetName
|
|
@@ -2011,8 +2019,19 @@ export function readXcodeAppTarget(
|
|
|
2011
2019
|
const words = settingList(flags)
|
|
2012
2020
|
const linked = new Set<TargetRef>(linkedTargets(ref).map((link) => link.target))
|
|
2013
2021
|
return words.flatMap((word, index) => {
|
|
2022
|
+
// ld finds `-l<name>` as lib<name>.a or lib<name>.dylib among the built products
|
|
2023
|
+
const library =
|
|
2024
|
+
word.startsWith('-l') && word.length > 2
|
|
2025
|
+
? word.slice(2)
|
|
2026
|
+
: words[index - 1] === '-l'
|
|
2027
|
+
? word
|
|
2028
|
+
: undefined
|
|
2014
2029
|
const target =
|
|
2015
|
-
words[index - 1] === '-framework'
|
|
2030
|
+
words[index - 1] === '-framework'
|
|
2031
|
+
? byProduct.get(`${word}.framework`)
|
|
2032
|
+
: library
|
|
2033
|
+
? (byProduct.get(`lib${library}.a`) ?? byProduct.get(`lib${library}.dylib`))
|
|
2034
|
+
: undefined
|
|
2016
2035
|
if (!target || target === ref || linked.has(target)) return []
|
|
2017
2036
|
linked.add(target)
|
|
2018
2037
|
return [{ target, attributes: [] }]
|