Fix insertion effect for react native

This commit is contained in:
2023-12-01 23:23:24 +01:00
parent 0f3c274fc4
commit 5d0d9e1717
6 changed files with 12 additions and 9 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "yoshiki",
"version": "1.2.13",
"version": "1.2.14",
"author": "Zoe Roux <zoe.roux@sdg.moe> (https://github.com/zoriya)",
"license": "MIT",
"keywords": [

View File

@@ -20,10 +20,10 @@ import {
processStyleListWithChild,
assignChilds,
} from "../type";
import { isBreakpoints } from "../utils";
import { isBreakpoints, useForceRerender } from "../utils";
import { shorthandsFn } from "../shorthands";
import { StyleFunc, NativeCssFunc, EnhancedStyle } from "./type";
import { useReducer, useRef } from "react";
import { useRef } from "react";
const useBreakpoint = (): number => {
const { width } = useWindowDimensions();
@@ -61,10 +61,6 @@ const propertyMapper = (
return [[key, value]];
};
const useForceRerender = () => {
return useReducer((x) => x + 1, 0)[1];
};
type State = EnhancedStyle<ViewStyle | TextStyle | ImageStyle> | undefined;
export const useYoshiki = (_?: string) => {

View File

@@ -23,7 +23,7 @@ export const useYoshiki = (prefixKey?: string) => {
useInsertionEffect(() => {
registry.flushToBrowser();
}, [registry]);
});
const css: NativeCssFunc = (cssList, leftOvers) => {
const [css, parentKeys] = processStyleListWithoutChild(cssList);

View File

@@ -3,9 +3,14 @@
// Licensed under the MIT license. See LICENSE file in the project root for details.
//
import { useReducer } from "react";
import { breakpoints } from "./theme";
import { Breakpoints, processStyleList, StyleList, YoshikiStyle } from "./type";
export const useForceRerender = () => {
return useReducer((x) => x + 1, 0)[1];
};
export const isBreakpoints = <T>(value: unknown): value is Breakpoints<T> => {
if (typeof value !== "object" || !value) return false;
for (const v of Object.keys(value)) {

View File

@@ -14,7 +14,7 @@ import {
processStyleListWithoutChild,
WithChild,
} from "../type";
import { forceBreakpoint, isBreakpoints } from "../utils";
import { forceBreakpoint, isBreakpoints, useForceRerender } from "../utils";
import { StyleRegistry, useStyleRegistry } from "./registry";
import { shorthandsFn } from "../shorthands";

View File

@@ -55,6 +55,8 @@ export class StyleRegistry {
if (!this.styleElement) {
this.hydrate();
}
// Dont recompute css if no new rules was added.
if (!this.rules.length) return;
const [css] = this.flushToStyleString();