Skip to content
Closed
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
2 changes: 1 addition & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function App() {
return (
<>
<View className="justify-center items-center h-full">
<Text className="shadow-red-500 shadow-2xl">Test Component</Text>
<Text className="text-blue-500">Test Component</Text>
</View>
</>
);
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/compiler.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable */
import type { Debugger } from "debug";
import type {
AnimationDirection,
AnimationFillMode,
Expand All @@ -14,7 +15,7 @@ export interface CompilerOptions {
selectorPrefix?: string;
stylesheetOrder?: number;
features?: FeatureFlagRecord;
logger?: (message: string) => void;
logger?: (message: string) => void | Debugger;
/** Strip unused variables declarations. Defaults: false */
stripUnusedVariables?: boolean;
/** @internal */
Expand Down
34 changes: 17 additions & 17 deletions src/compiler/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,8 @@ export function parseUnparsed(
case "hsla":
case "linear-gradient":
case "radial-gradient":
case "cubic-bezier":
case "steps":
return unparsedFunction(tokenOrValue, builder);
case "hairlineWidth":
return [{}, tokenOrValue.value.name, []];
Expand All @@ -999,31 +1001,29 @@ export function parseUnparsed(
case "token":
switch (tokenOrValue.value.type) {
case "string":
case "number":
case "ident": {
const value = tokenOrValue.value.value;
if (typeof value === "string") {
if (!allowAuto && value === "auto") {
builder.addWarning("value", value);
return;
}
if (!allowAuto && value === "auto") {
builder.addWarning("value", value);
return;
}

if (value === "inherit") {
builder.addWarning("value", value);
return;
}
if (value === "inherit") {
builder.addWarning("value", value);
return;
}

if (value === "true") {
return true;
} else if (value === "false") {
return false;
} else {
return value;
}
if (value === "true") {
return true;
} else if (value === "false") {
return false;
} else {
return value;
}
}
case "number": {
return round(tokenOrValue.value.value);
}
case "function":
builder.addWarning("value", tokenOrValue.value.value);
return;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/keyframes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function extractKeyFrames(
switch (selector.type) {
case "percentage":
return frame.selectors.length > 1
? `${selector.value}%`
? `${selector.value * 100}%`
: selector.value;
case "from":
case "to":
Expand Down
9 changes: 8 additions & 1 deletion src/compiler/stylesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ export class StylesheetBuilder {
const [delayed, usesVariables] = postProcessStyleFunction(value);

this.rule.d ??= [];
if (value[1] === "@animation") {
this.rule.a ??= true;
}

if (usesVariables) {
this.rule.dv = 1;
Expand All @@ -209,6 +212,10 @@ export class StylesheetBuilder {
delayed || usesVariables,
);
} else {
if (property.startsWith("animation-")) {
this.rule.a ??= true;
}

this.rule.d ??= [];
this.pushDescriptor(property, value, this.rule.d);
}
Expand Down Expand Up @@ -370,7 +377,7 @@ export class StylesheetBuilder {
}

this.animationDeclarations = [];
this.staticDeclarations = {};
this.staticDeclarations = undefined;
this.animationFrames.push([progress, this.animationDeclarations]);
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/runtime/native/conditions/guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ export function testGuards(
break;
}

// if (result) {
// console.log(`Guard ${guard[0]}:${guard[1]} failed`);
// }

return result;
});
}
26 changes: 15 additions & 11 deletions src/runtime/native/react/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export function updateRules(
}

// Generate a StyleObservable for this unique set of rules / variables
const stylesObs = stylesFamily(generateHash(state, rules), rules);
const stylesObs = stylesFamily(generateStateHash(state, rules), rules);

// Get the guards without subscribing to the observable
// We will subscribe within the render using the StyleEffect
Expand Down Expand Up @@ -277,21 +277,12 @@ function pushInlineRule(
let hashKeyCount = 0;
const hashKeyFamily = weakFamily(() => hashKeyCount++);

/**
* Quickly generate a unique hash for a set of numbers.
* This is not a cryptographic hash, but it is fast and has a low chance of collision.
*/
const MOD = 9007199254740871; // Largest prime within safe integer range 2^53
const PRIME = 31; // A smaller prime for mixing
export function generateHash(
export function generateStateHash(
state: ComponentState,
iterableKeys?: Iterable<WeakKey>,
variables?: WeakKey,
inlineVars?: Set<WeakKey>,
): string {
let hash = 0;
let product = 1; // Used for mixing to enhance uniqueness

if (!iterableKeys) {
return "";
}
Expand All @@ -306,6 +297,19 @@ export function generateHash(
keys.push(...inlineVars);
}

return generateHash(keys);
}

/**
* Quickly generate a unique hash for a set of numbers.
* This is not a cryptographic hash, but it is fast and has a low chance of collision.
*/
const MOD = 9007199254740871; // Largest prime within safe integer range 2^53
const PRIME = 31; // A smaller prime for mixing
export function generateHash(keys: WeakKey[]): string {
let hash = 0;
let product = 1; // Used for mixing to enhance uniqueness

for (const key of keys) {
if (!key) continue; // Skip if key is undefined

Expand Down
Loading