9
import {
10
BUILTIN_SHAPES,
11
BuiltInArrayId,
12
+ BuiltInMixedReadonlyId,
13
BuiltInUseEffectHookId,
14
BuiltInUseInsertionEffectHookId,
15
BuiltInUseLayoutEffectHookId,
414
"globalThis",
415
addObject(DEFAULT_SHAPES, "globalThis", TYPED_GLOBALS)
416
);
417
+
418
+export function installReAnimatedTypes(
419
+ globals: GlobalRegistry,
420
+ registry: ShapeRegistry
421
+): void {
422
+ // hooks that freeze args and return frozen value
423
+ const frozenHooks = [
424
+ "useFrameCallback",
425
+ "useAnimatedStyle",
426
+ "useAnimatedProps",
427
+ "useAnimatedScrollHandler",
428
+ "useAnimatedReaction",
429
+ "useWorkletCallback",
430
+ ];
431
+ for (const hook of frozenHooks) {
432
+ globals.set(
433
+ hook,
434
+ addHook(registry, {
435
+ positionalParams: [],
436
+ restParam: Effect.Freeze,
437
+ returnType: { kind: "Object", shapeId: BuiltInMixedReadonlyId },
438
+ returnValueKind: ValueKind.Frozen,
439
+ noAlias: true,
440
+ calleeEffect: Effect.Read,
441
+ hookKind: "Custom",
442
+ })
443
+ );
444
+ }
445
+
446
+ /**
447
+ * hooks that return a mutable value. ideally these should be modelled as a
448
+ * ref, but this works for now.
449
+ */
450
+ const mutableHooks = ["useSharedValue", "useDerivedValue"];
451
+ for (const hook of mutableHooks) {
452
+ globals.set(
453
+ hook,
454
+ addHook(registry, {
455
+ positionalParams: [],
456
+ restParam: Effect.Freeze,
457
+ returnType: { kind: "Poly" },
458
+ returnValueKind: ValueKind.Mutable,
459
+ noAlias: true,
460
+ calleeEffect: Effect.Read,
461
+ hookKind: "Custom",
462
+ })
463
+ );
464
+ }
465
+
466
+ // functions that return mutable value
467
+ const funcs = [
468
+ "withTiming",
469
+ "withSpring",
470
+ "createAnimatedPropAdapter",
471
+ "withDecay",
472
+ "withRepeat",
473
+ "runOnUI",
474
+ "executeOnUIRuntimeSync",
475
+ ];
476
+ for (const fn of funcs) {
477
+ globals.set(
478
+ fn,
479
+ addFunction(registry, [], {
480
+ positionalParams: [],
481
+ restParam: Effect.Read,
482
+ returnType: { kind: "Poly" },
483
+ calleeEffect: Effect.Read,
484
+ returnValueKind: ValueKind.Mutable,
485
+ noAlias: true,
486
+ })
487
+ );
488
+ }
489
+}