Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions packages/react/runtime/src/gesture/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
// LICENSE file in the root directory of this source tree.
import type { Worklet } from '@lynx-js/react/worklet-runtime/bindings';

export enum GestureTypeInner {
COMPOSED = -1,
PAN = 0,
FLING = 1,
DEFAULT = 2,
TAP = 3,
LONGPRESS = 4,
ROTATION = 5,
PINCH = 6,
NATIVE = 7,
}
export const GestureTypeInner = {
COMPOSED: -1,
PAN: 0,
FLING: 1,
DEFAULT: 2,
TAP: 3,
LONGPRESS: 4,
ROTATION: 5,
PINCH: 6,
NATIVE: 7,
} as const;

export type GestureTypeInner = (typeof GestureTypeInner)[keyof typeof GestureTypeInner];

export interface GestureKind {
type: GestureTypeInner;
Expand All @@ -22,7 +24,7 @@ export interface GestureKind {
}

export interface ComposedGesture extends GestureKind {
type: GestureTypeInner.COMPOSED;
type: (typeof GestureTypeInner)['COMPOSED'];
gestures: GestureKind[];
}

Expand Down
30 changes: 17 additions & 13 deletions packages/react/runtime/src/lifecycleConstant.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
// Copyright 2024 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.
export const enum LifecycleConstant {
firstScreen = 'rLynxFirstScreen',
updateFromRoot = 'updateFromRoot',
globalEventFromLepus = 'globalEventFromLepus',
jsReady = 'rLynxJSReady',
patchUpdate = 'rLynxChange',
publishEvent = 'rLynxPublishEvent',
updateMTRefInitValue = 'rLynxChangeRefInitValue',
}
export const LifecycleConstant = {
firstScreen: 'rLynxFirstScreen',
updateFromRoot: 'updateFromRoot',
globalEventFromLepus: 'globalEventFromLepus',
jsReady: 'rLynxJSReady',
patchUpdate: 'rLynxChange',
publishEvent: 'rLynxPublishEvent',
updateMTRefInitValue: 'rLynxChangeRefInitValue',
} as const;

export type LifecycleConstant = (typeof LifecycleConstant)[keyof typeof LifecycleConstant];

export interface FirstScreenData {
root: string;
jsReadyEventIdSwap: Record<string | number, number>;
}

export const enum NativeUpdateDataType {
UPDATE = 0,
RESET = 1,
}
export const NativeUpdateDataType = {
UPDATE: 0,
RESET: 1,
} as const;

export type NativeUpdateDataType = (typeof NativeUpdateDataType)[keyof typeof NativeUpdateDataType];
26 changes: 12 additions & 14 deletions packages/react/runtime/src/opcodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import { componentAtIndexFactory, enqueueComponentFactory, gRecycleMap, gSignMap
import { CHILDREN } from './renderToOpcodes/constants.js';
import { SnapshotInstance } from './snapshot.js';

const enum Opcode {
Begin = 0,
End,
Attr,
Text,
}
const OpcodeBegin = 0;
const OpcodeEnd = 1;
const OpcodeAttr = 2;
const OpcodeText = 3;

interface SSRFiberElement {
ssrID: string;
Expand All @@ -28,7 +26,7 @@ export function ssrHydrateByOpcodes(
for (let i = 0; i < opcodes.length;) {
const opcode = opcodes[i];
switch (opcode) {
case Opcode.Begin: {
case OpcodeBegin: {
const p = top;
const [type, __id, elements] = opcodes[i + 1] as SSRSnapshotInstance;
top = new SnapshotInstance(type, __id);
Expand All @@ -39,7 +37,7 @@ export function ssrHydrateByOpcodes(
i += 2;
break;
}
case Opcode.End: {
case OpcodeEnd: {
// @ts-ignore
top[CHILDREN] = undefined;

Expand Down Expand Up @@ -75,15 +73,15 @@ export function ssrHydrateByOpcodes(
i += 1;
break;
}
case Opcode.Attr: {
case OpcodeAttr: {
const key = opcodes[i + 1];
const value = opcodes[i + 2];
top.setAttribute(key, value);

i += 3;
break;
}
case Opcode.Text: {
case OpcodeText: {
const [[type, __id, elements], text] = opcodes[i + 1] as [SSRSnapshotInstance, string];
const s = new SnapshotInstance(type, __id);
s.setAttribute(0, text);
Expand All @@ -103,7 +101,7 @@ export function renderOpcodesInto(opcodes: any[], into: SnapshotInstance): void
for (let i = 0; i < opcodes.length;) {
const opcode = opcodes[i];
switch (opcode) {
case Opcode.Begin: {
case OpcodeBegin: {
const p = top;
top = opcodes[i + 1];
// @ts-ignore
Expand All @@ -118,7 +116,7 @@ export function renderOpcodesInto(opcodes: any[], into: SnapshotInstance): void
i += 2;
break;
}
case Opcode.End: {
case OpcodeEnd: {
// @ts-ignore
top[CHILDREN] = undefined;

Expand All @@ -129,15 +127,15 @@ export function renderOpcodesInto(opcodes: any[], into: SnapshotInstance): void
i += 1;
break;
}
case Opcode.Attr: {
case OpcodeAttr: {
const key = opcodes[i + 1];
const value = opcodes[i + 2];
top.setAttribute(key, value);

i += 3;
break;
}
case Opcode.Text: {
case OpcodeText: {
const text = opcodes[i + 1];
const s = new SnapshotInstance(null as unknown as string);
if (__ENABLE_SSR__) {
Expand Down
18 changes: 10 additions & 8 deletions packages/react/runtime/src/snapshot/dynamicPartType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
* Types of dynamic parts that can be updated in a snapshot
* These are determined at compile time through static analysis
*/
export const enum DynamicPartType {
Attr = 0, // Regular attribute updates
Spread, // Spread operator in JSX
Slot, // Slot for component children
Children, // Regular children updates
ListChildren, // List/array children updates
MultiChildren, // Multiple children updates (compat layer)
}
export const DynamicPartType = {
Attr: 0, // Regular attribute updates
Spread: 1, // Spread operator in JSX
Slot: 2, // Slot for component children
Children: 3, // Regular children updates
ListChildren: 4, // List/array children updates
MultiChildren: 5, // Multiple children updates (compat layer)
} as const;

export type DynamicPartType = (typeof DynamicPartType)[keyof typeof DynamicPartType];
Loading