peachsim 0.1.2305 → 0.1.2306

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.
Files changed (84) hide show
  1. package/dist-lib/agent-daemon-client.cjs +1 -1
  2. package/dist-lib/agent-events.cjs +1 -1
  3. package/dist-lib/attached-projects.cjs +1 -1
  4. package/dist-lib/auth/shared-session.cjs +1 -1
  5. package/dist-lib/backend-origin.cjs +1 -1
  6. package/dist-lib/beta.cjs +1 -1
  7. package/dist-lib/beta.mjs +1 -1
  8. package/dist-lib/bridge-constants.cjs +1 -1
  9. package/dist-lib/bridge-contract-input.cjs +1 -1
  10. package/dist-lib/bridge-contract-input.mjs +1 -1
  11. package/dist-lib/bridge-contract.cjs +1 -1
  12. package/dist-lib/bridge-contract.mjs +1 -1
  13. package/dist-lib/bundle-channel.cjs +149 -26
  14. package/dist-lib/capture-contract.cjs +1 -1
  15. package/dist-lib/capture-contract.mjs +1 -1
  16. package/dist-lib/cloud-contract.cjs +1 -1
  17. package/dist-lib/cloud-contract.mjs +1 -1
  18. package/dist-lib/cloud-test-args.cjs +1 -1
  19. package/dist-lib/cloud-test-args.mjs +1 -1
  20. package/dist-lib/cloud.cjs +1 -1
  21. package/dist-lib/cloud.mjs +1 -1
  22. package/dist-lib/config.cjs +1 -1
  23. package/dist-lib/config.mjs +1 -1
  24. package/dist-lib/detox/index.cjs +1 -1
  25. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  26. package/dist-lib/expo-swift-bundle.cjs +148 -25
  27. package/dist-lib/expo-swift-metadata.cjs +1 -1
  28. package/dist-lib/expo-swift-metadata.mjs +1 -1
  29. package/dist-lib/home-paths.cjs +1 -1
  30. package/dist-lib/host/bridge-host.cjs +149 -26
  31. package/dist-lib/host/fetch-proxy-handler.cjs +5 -4
  32. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  33. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  34. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  35. package/dist-lib/host/websocket-proxy.cjs +1 -1
  36. package/dist-lib/index.cjs +5 -4
  37. package/dist-lib/jump-to-source-babel.cjs +1 -1
  38. package/dist-lib/jump-to-source-native.cjs +1 -1
  39. package/dist-lib/kotlin-host.cjs +1 -1
  40. package/dist-lib/menu.cjs +1 -1
  41. package/dist-lib/menu.mjs +1 -1
  42. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  43. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  44. package/dist-lib/metro-production-bundle.cjs +1 -1
  45. package/dist-lib/metro-production-bundle.mjs +1 -1
  46. package/dist-lib/metro.cjs +5 -4
  47. package/dist-lib/native-app-identity-project.cjs +2 -2
  48. package/dist-lib/native-app-identity-project.mjs +2 -2
  49. package/dist-lib/native-app-identity.cjs +1 -1
  50. package/dist-lib/native-app-identity.mjs +1 -1
  51. package/dist-lib/native-firebase-metadata.cjs +1 -1
  52. package/dist-lib/native-firebase-metadata.mjs +1 -1
  53. package/dist-lib/pdfium-raster.cjs +1 -1
  54. package/dist-lib/pdfium-raster.mjs +1 -1
  55. package/dist-lib/plist.cjs +1 -1
  56. package/dist-lib/plist.mjs +1 -1
  57. package/dist-lib/profiles.cjs +1 -1
  58. package/dist-lib/public-brand.cjs +1 -1
  59. package/dist-lib/public-origins-lib-esm.json +24 -24
  60. package/dist-lib/public-origins-lib.json +53 -53
  61. package/dist-lib/react-native-host-modules.cjs +1 -1
  62. package/dist-lib/react-native-host-modules.mjs +1 -1
  63. package/dist-lib/reap-browser.cjs +1 -1
  64. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  65. package/dist-lib/sdk.cjs +1 -1
  66. package/dist-lib/sdk.mjs +1 -1
  67. package/dist-lib/skills.cjs +149 -26
  68. package/dist-lib/swift-compile.cjs +2 -2
  69. package/dist-lib/swift-compile.mjs +2 -2
  70. package/dist-lib/swift-package.cjs +1 -1
  71. package/dist-lib/swift-package.mjs +1 -1
  72. package/dist-lib/swift-submit.cjs +1 -1
  73. package/dist-lib/swift-submit.mjs +1 -1
  74. package/dist-lib/swift-toolchain.cjs +1 -1
  75. package/dist-lib/swift.cjs +1 -1
  76. package/dist-lib/vite-swift.cjs +4 -4
  77. package/dist-lib/vite.cjs +5 -4
  78. package/dist-lib/worklet-executable.cjs +1 -1
  79. package/dist-lib/worklet-executable.mjs +1 -1
  80. package/kotlin/sdk.tar.gz +0 -0
  81. package/package.json +1 -1
  82. package/sdk/ios/System/Library/Frameworks/QuickLook.framework/Headers/QLPreviewController.h +1 -1
  83. package/src/native-static-libraries.ts +1 -1
  84. package/src/turbo-source.ts +148 -22
@@ -43,6 +43,7 @@ import {
43
43
  } from './podspec-sources'
44
44
  import { readPackageFile, relativeInside } from './swift-source-file'
45
45
  import { MAX_SWIFT_COMPILE_SOURCE_BYTES } from './swift-submit'
46
+ import { SWIFT_NATIVE_INPUT_ROOT, type SwiftNativeHeaderMap } from './swiftContract'
46
47
  import {
47
48
  installedFabricSources,
48
49
  type FabricPodSources,
@@ -53,7 +54,6 @@ import { installedXcodeWorkspace, readXcodeAppTarget } from './xcode-project'
53
54
  import type { ReactNativeCoreMode } from './react-native-core'
54
55
  import type { SwiftCompileInput } from './swift-compile'
55
56
  import type { SwiftPackageTarget } from './swift-package'
56
- import type { SwiftNativeHeaderMap } from './swiftContract'
57
57
 
58
58
  type TurboPackage = { name: string; version: string; root: string }
59
59
 
@@ -1259,15 +1259,17 @@ export async function collectTurboSources(options: {
1259
1259
  flattensPublicHeaders: false,
1260
1260
  bridgingHeader: null,
1261
1261
  prefixHeader,
1262
- headerSearchPaths: [
1263
- `${targetPath(targetName)}/include`,
1264
- `${targetPath(TURBO_CORE_TARGET)}/include`,
1265
- ],
1262
+ headerSearchPaths: [`${targetPath(targetName)}/include`],
1266
1263
  userHeaderSearchPaths: [],
1267
1264
  frameworkSearchPaths: [],
1268
1265
  headerMaps: [],
1269
1266
  productHeaders: {},
1270
- flags: [],
1267
+ // TurboCore's aliased React headers compile the units but never reach
1268
+ // a Swift importer, whose React module is the app's own
1269
+ flags: [
1270
+ '-I',
1271
+ `${SWIFT_NATIVE_INPUT_ROOT}/${targetPath(TURBO_CORE_TARGET)}/include`,
1272
+ ],
1271
1273
  importerFlags: [],
1272
1274
  cxxFlags: [],
1273
1275
  fileFlags: {},
@@ -2923,7 +2925,8 @@ ${
2923
2925
  @end
2924
2926
 
2925
2927
  // an app's Fabric component views, which its own Fabric host defines
2926
- extern "C" void peachInstallFabricViews(facebook::jsi::Runtime &runtime) __attribute__((weak));
2928
+ void peachInstallFabricViews(facebook::jsi::Runtime &runtime, std::shared_ptr<facebook::react::CallInvoker> invoker) __attribute__((weak));
2929
+ void peachTeardownFabricViews() __attribute__((weak));
2927
2930
 
2928
2931
  // UIKitCore: the key window and root view controller an app delegate makes at launch
2929
2932
  extern "C" void PeachLaunchReactNativeWindow(void);
@@ -2945,6 +2948,7 @@ extern "C" void peachTurboInitialize() {
2945
2948
  auto& runtime = peach::jsi_runtime::create(
2946
2949
  [] { invoker->drain(); },
2947
2950
  [] {
2951
+ if (peachTeardownFabricViews) peachTeardownFabricViews();
2948
2952
  [manager invalidate];
2949
2953
  manager = nil;
2950
2954
  delegate = nil;
@@ -3006,7 +3010,7 @@ ${
3006
3010
  }];
3007
3011
  [decorator.moduleRegistry setTurboModuleRegistry:manager];
3008
3012
  [manager installJSBindings:runtime];
3009
- if (peachInstallFabricViews) peachInstallFabricViews(runtime);
3013
+ if (peachInstallFabricViews) peachInstallFabricViews(runtime, invoker);
3010
3014
  }
3011
3015
 
3012
3016
  // the screenshot the device took, as UIKit posts it to every observer in the
@@ -3057,13 +3061,22 @@ const FABRIC_HOST_INCLUDES = `#import <Foundation/Foundation.h>
3057
3061
  #import <React/RCTComponentViewFactory.h>
3058
3062
  #import <React/RCTComponentViewProtocol.h>
3059
3063
  #import <React/RCTComponentViewRegistry.h>
3064
+ #import <ReactCommon/RCTTurboModule.h>
3065
+ #include <ReactCommon/CallInvoker.h>
3060
3066
  #include <react/renderer/componentregistry/ComponentDescriptorRegistry.h>
3067
+ #include <react/renderer/core/EventBeat.h>
3068
+ #include <react/renderer/core/EventDispatcher.h>
3069
+ #include <react/renderer/core/EventQueueProcessor.h>
3070
+ #include <react/renderer/core/InstanceHandle.h>
3061
3071
  #include <react/renderer/core/LayoutMetrics.h>
3062
3072
  #include <react/renderer/core/PropsParserContext.h>
3063
3073
  #include <react/renderer/core/RawProps.h>
3074
+ #include <react/renderer/core/StateUpdate.h>
3075
+ #include <react/renderer/runtimescheduler/RuntimeScheduler.h>
3064
3076
  #include <react/utils/ContextContainer.h>
3065
3077
  #include <cstdio>
3066
3078
  #include <cstdlib>
3079
+ #include <optional>
3067
3080
  #include <unordered_map>
3068
3081
  #include <jsi/jsi.h>
3069
3082
 
@@ -3074,8 +3087,12 @@ using namespace facebook;
3074
3087
  // mounts them (RCTPerformMountInstructions): the component view factory with
3075
3088
  // the app's third-party components, one registry dequeuing and recycling
3076
3089
  // 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.
3090
+ // passes. each view's family carries the instance handle the engine passes,
3091
+ // so its event emitter dispatches through an EventDispatcher whose pipe calls
3092
+ // the engine as UIManagerBinding::dispatchEventToJS calls React, and its state
3093
+ // updates reach the view as UIManager::updateState's commit would. the engine
3094
+ // lays the view out and paints its style; the view is the content of a root of
3095
+ // this process.
3079
3096
  function fabricHostSource(views: readonly FabricComponent[]): string {
3080
3097
  const entries = views
3081
3098
  .map(
@@ -3098,13 +3115,20 @@ namespace {
3098
3115
  struct PeachFabricView {
3099
3116
  react::ComponentHandle handle;
3100
3117
  const react::ComponentDescriptor *descriptor;
3118
+ react::ShadowNodeFamily::Shared family;
3101
3119
  react::Props::Shared props;
3120
+ react::State::Shared state;
3102
3121
  react::LayoutMetrics layoutMetrics;
3103
3122
  };
3104
3123
  PeachFabricComponents *fabricComponents;
3105
3124
  RCTComponentViewRegistry *fabricRegistry;
3106
- std::shared_ptr<const react::ContextContainer> fabricContext;
3125
+ std::shared_ptr<react::ContextContainer> fabricContext;
3107
3126
  react::ComponentDescriptorRegistry::Shared fabricDescriptors;
3127
+ std::shared_ptr<react::CallInvoker> fabricInvoker;
3128
+ std::shared_ptr<react::RuntimeScheduler> fabricScheduler;
3129
+ std::shared_ptr<const void> fabricOwner;
3130
+ std::shared_ptr<const react::EventDispatcher> fabricDispatcher;
3131
+ std::optional<jsi::Function> fabricEventHandler;
3108
3132
  std::unordered_map<int, PeachFabricView> fabricViews;
3109
3133
  int nextFabricView = 1;
3110
3134
  std::string fabricNames = ${JSON.stringify(views.map(({ name }) => name).join('\n'))};
@@ -3123,32 +3147,112 @@ react::Props::Shared fabricCloneProps(jsi::Runtime &rt, const PeachFabricView &v
3123
3147
  return view.descriptor->cloneProps(context, view.props, react::RawProps(rt, props));
3124
3148
  }
3125
3149
 
3150
+ // the beat React Native's run loop observer gives: queued events flush once
3151
+ // the call that queued them returns
3152
+ class PeachFabricEventBeat final : public react::EventBeat {
3153
+ public:
3154
+ PeachFabricEventBeat(std::shared_ptr<OwnerBox> ownerBox, react::RuntimeScheduler &scheduler)
3155
+ : EventBeat(ownerBox, scheduler), box(std::move(ownerBox)) {}
3156
+ void request() const override {
3157
+ EventBeat::request();
3158
+ std::weak_ptr<const void> owner = box->owner;
3159
+ fabricInvoker->invokeAsync([this, owner](jsi::Runtime &) {
3160
+ if (owner.lock()) induce();
3161
+ });
3162
+ }
3163
+
3164
+ private:
3165
+ std::shared_ptr<OwnerBox> box;
3166
+ };
3167
+
3168
+ // UIManager::updateState reads a state's data as State's friend; a member
3169
+ // pointer named through a derived class reaches the same accessor
3170
+ struct PeachStateData : react::State {
3171
+ static constexpr auto data = &PeachStateData::getDataPointer;
3172
+ };
3173
+
3174
+ // UIManager::dispatchEventToJS: the instance handle the engine gave the view,
3175
+ // the event type and its payload with the target tag and timestamp
3176
+ void fabricDispatchEvent(
3177
+ jsi::Runtime &rt,
3178
+ react::EventTarget *target,
3179
+ const std::string &type,
3180
+ react::ReactEventPriority,
3181
+ const react::EventPayload &eventPayload,
3182
+ react::HighResTimeStamp timestamp) {
3183
+ auto payload = eventPayload.asJSIValue(rt);
3184
+ if (payload.isNull() || !fabricEventHandler || !target) return;
3185
+ auto handle = target->getInstanceHandle(rt);
3186
+ if (handle.isUndefined() || handle.isNull()) return;
3187
+ if (payload.isObject()) {
3188
+ auto object = payload.asObject(rt);
3189
+ object.setProperty(rt, "target", target->getTag());
3190
+ if (!object.hasProperty(rt, "timeStamp"))
3191
+ object.setProperty(rt, "timeStamp", timestamp.toDOMHighResTimeStamp());
3192
+ }
3193
+ fabricEventHandler->call(rt, std::move(handle), jsi::String::createFromUtf8(rt, type), std::move(payload));
3194
+ }
3195
+
3196
+ // UIManager::updateState with the engine's tree in place of the shadow tree:
3197
+ // the view's next state, then the update its commit would mount
3198
+ void fabricUpdateState(const react::StateUpdate &update) {
3199
+ int tag = update.family->getTag();
3200
+ auto found = fabricViews.find(tag);
3201
+ if (found == fabricViews.end() || !found->second.state) return;
3202
+ auto &view = found->second;
3203
+ auto data = update.callback(((*view.state).*PeachStateData::data)());
3204
+ if (!data) return;
3205
+ auto oldState = view.state;
3206
+ view.state = view.descriptor->createState(*view.family, data);
3207
+ UIView<RCTComponentViewProtocol> *componentView = [fabricRegistry componentViewDescriptorWithTag:tag].view;
3208
+ [componentView updateState:view.state oldState:oldState];
3209
+ [componentView finalizeUpdates:RNComponentViewUpdateMaskState];
3210
+ }
3211
+
3126
3212
  } // namespace
3127
3213
 
3128
- extern "C" void peachInstallFabricViews(jsi::Runtime &rt) {
3214
+ void peachInstallFabricViews(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> invoker) {
3215
+ fabricInvoker = std::move(invoker);
3129
3216
  fabricComponents = [PeachFabricComponents new];
3130
3217
  RCTComponentViewFactory *factory = [RCTComponentViewFactory currentComponentViewFactory];
3131
3218
  factory.thirdPartyFabricComponentsProvider = fabricComponents;
3132
3219
  fabricRegistry = [RCTComponentViewRegistry new];
3133
- fabricContext = std::make_shared<const react::ContextContainer>();
3134
- react::ComponentDescriptorParameters parameters{{}, fabricContext, nullptr};
3220
+ fabricContext = std::make_shared<react::ContextContainer>();
3221
+ fabricScheduler = std::make_shared<react::RuntimeScheduler>(
3222
+ [](std::function<void(jsi::Runtime &)> &&work) { fabricInvoker->invokeAsync(std::move(work)); });
3223
+ fabricContext->insert(react::RuntimeSchedulerKey, std::weak_ptr<react::RuntimeScheduler>(fabricScheduler));
3224
+ fabricOwner = std::make_shared<int>(0);
3225
+ auto box = std::make_shared<react::EventBeat::OwnerBox>();
3226
+ box->owner = fabricOwner;
3227
+ auto conclusion = [](jsi::Runtime &rt) { fabricScheduler->callExpiredTasks(rt); };
3228
+ fabricDispatcher = std::make_shared<const react::EventDispatcher>(
3229
+ react::EventQueueProcessor(fabricDispatchEvent, conclusion, fabricUpdateState, std::weak_ptr<react::EventLogger>()),
3230
+ std::make_unique<PeachFabricEventBeat>(box, *fabricScheduler),
3231
+ fabricUpdateState,
3232
+ std::weak_ptr<react::EventLogger>());
3233
+ react::ComponentDescriptorParameters parameters{fabricDispatcher, fabricContext, nullptr};
3135
3234
  fabricDescriptors = [factory createComponentDescriptorRegistryWithParameters:parameters];
3136
3235
  auto views = jsi::Object(rt);
3137
3236
  auto method = [&](const char *name, unsigned count, jsi::HostFunctionType body) {
3138
3237
  views.setProperty(rt, name, jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, name), count, std::move(body)));
3139
3238
  };
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 {
3239
+ // create(name, instanceHandle, props), Create then Insert: the family the
3240
+ // handle's events resolve through, the first props, the initial state, and
3241
+ // the layout the view has before the engine measures it
3242
+ method("create", 3, [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, size_t) -> jsi::Value {
3143
3243
  const auto &descriptor = fabricDescriptors->at(args[0].asString(rt).utf8(rt));
3144
3244
  int tag = nextFabricView++;
3145
- auto &view = fabricViews.emplace(tag, PeachFabricView{descriptor.getComponentHandle(), &descriptor, nullptr, {}}).first->second;
3146
- view.props = fabricCloneProps(rt, view, args[1]);
3245
+ auto family = descriptor.createFamily(
3246
+ {.tag = tag, .surfaceId = -1, .instanceHandle = std::make_shared<const react::InstanceHandle>(rt, args[1], tag)});
3247
+ auto &view = fabricViews.emplace(tag, PeachFabricView{descriptor.getComponentHandle(), &descriptor, family, nullptr, nullptr, {}}).first->second;
3248
+ view.props = fabricCloneProps(rt, view, args[2]);
3249
+ view.state = descriptor.createInitialState(view.props, family);
3250
+ family->getEventEmitter()->setEnabled(true);
3147
3251
  UIView<RCTComponentViewProtocol> *componentView =
3148
3252
  [fabricRegistry dequeueComponentViewWithComponentHandle:view.handle tag:tag].view;
3149
3253
  [componentView updateProps:view.props oldProps:nullptr];
3150
- [componentView updateEventEmitter:nullptr];
3151
- [componentView updateState:nullptr oldState:nullptr];
3254
+ [componentView updateEventEmitter:family->getEventEmitter()];
3255
+ [componentView updateState:view.state oldState:nullptr];
3152
3256
  [componentView updateLayoutMetrics:view.layoutMetrics oldLayoutMetrics:react::EmptyLayoutMetrics];
3153
3257
  [componentView finalizeUpdates:RNComponentViewUpdateMaskAll];
3154
3258
  return jsi::Value(tag);
@@ -3178,19 +3282,41 @@ extern "C" void peachInstallFabricViews(jsi::Runtime &rt) {
3178
3282
  [componentView finalizeUpdates:RNComponentViewUpdateMaskLayoutMetrics];
3179
3283
  return jsi::Value::undefined();
3180
3284
  });
3181
- // Remove then Delete: the registry recycles the view
3285
+ // Remove then Delete: the family's emitter stops at once, as an unmounted
3286
+ // family's does, and the registry recycles the view
3182
3287
  method("drop", 1, [](jsi::Runtime &, const jsi::Value &, const jsi::Value *args, size_t) -> jsi::Value {
3183
3288
  int tag = static_cast<int>(args[0].asNumber());
3184
3289
  auto &view = fabricView(tag);
3290
+ view.family->getEventEmitter()->setEnabled(false);
3185
3291
  RCTComponentViewDescriptor descriptor = [fabricRegistry componentViewDescriptorWithTag:tag];
3186
3292
  [descriptor.view removeFromSuperview];
3187
3293
  [fabricRegistry enqueueComponentViewWithComponentHandle:view.handle tag:tag componentViewDescriptor:descriptor];
3188
3294
  fabricViews.erase(tag);
3189
3295
  return jsi::Value::undefined();
3190
3296
  });
3297
+ // RCTMountingManager::dispatchCommand: the view's handleCommand:args:
3298
+ method("command", 3, [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, size_t) -> jsi::Value {
3299
+ int tag = static_cast<int>(args[0].asNumber());
3300
+ fabricView(tag);
3301
+ NSArray *commandArgs = react::TurboModuleConvertUtils::convertJSIValueToObjCObject(rt, args[2], fabricInvoker);
3302
+ [[fabricRegistry componentViewDescriptorWithTag:tag].view handleCommand:@(args[1].asString(rt).utf8(rt).c_str())
3303
+ args:commandArgs];
3304
+ return jsi::Value::undefined();
3305
+ });
3306
+ // the function React's dispatchEvent stands for: (instanceHandle, type, payload)
3307
+ method("setEventHandler", 1, [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, size_t) -> jsi::Value {
3308
+ fabricEventHandler = args[0].asObject(rt).asFunction(rt);
3309
+ return jsi::Value::undefined();
3310
+ });
3191
3311
  rt.global().setProperty(rt, "peachFabricViews", std::move(views));
3192
3312
  }
3193
3313
 
3314
+ // the runtime's functions go before the runtime does
3315
+ void peachTeardownFabricViews() {
3316
+ fabricOwner.reset();
3317
+ fabricEventHandler.reset();
3318
+ }
3319
+
3194
3320
  extern "C" void *peach_fabric_view_content(int tag) {
3195
3321
  return (__bridge_retained void *)[fabricRegistry componentViewDescriptorWithTag:tag].view;
3196
3322
  }