Skip to content

Commit f5c1dcc

Browse files
fix rn style extensoin to allow only valid rn properties
1 parent d066ad1 commit f5c1dcc

9 files changed

Lines changed: 58 additions & 14 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export type ReactNativeBlurConfig = {
2+
layer: "none" | ReactNativeExpoBlurConfig | ReactNativeCommunityBlurConfig;
3+
background: "none" | null;
4+
image: ReactNativeImageBlurConfig;
5+
};
6+
7+
/**
8+
* RN has a built-in blur effect for image based elements - Image, BackgroundImage
9+
*/
10+
interface ReactNativeImageBlurConfig {}
11+
12+
interface ReactNativeExpoBlurConfig {
13+
module: "expo-blur";
14+
}
15+
16+
interface ReactNativeCommunityBlurConfig {
17+
module: "@react-native-community/blur";
18+
}

packages/builder-config/framework-reactnative/reactnative-config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { ReactNativeSvgConfig } from "./reactnative-config-svg";
88
import type { ReactNativeGradientConfig } from "./reactnative-config-gradient";
99
import type { ReactNativeTextGradientConfig } from "./reactnative-config-gradient-text";
1010
import type { ReactNativeShadowConfig } from "./reactnative-config-shadow";
11+
import type { ReactNativeBlurConfig } from "./reactnative-config-blur";
1112

1213
export interface ReactNativeFrameworkConfig {
1314
framework: "react-native";
@@ -17,6 +18,10 @@ export interface ReactNativeFrameworkConfig {
1718
gradient_text: ReactNativeTextGradientConfig;
1819
shadow: ReactNativeShadowConfig;
1920
svg: ReactNativeSvgConfig;
21+
/**
22+
* @deprecated not supported at this moment - wip
23+
*/
24+
blur?: ReactNativeBlurConfig;
2025
component_declaration_style: {
2126
exporting_style: ReactComponentExportingCofnig;
2227
// not supported yet

packages/designto-react-native/tokens-to-rn-widget/compose-wrapped-with-blurred.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
import * as core from "@reflect-ui/core";
22
import { Composer } from ".";
3-
import * as css from "@web-builder/styles";
3+
import type { ViewStyle } from "react-native";
44

5+
/**
6+
* @deprecated Blur for RN not supported yet.
7+
*
8+
* Learn more
9+
* - https://stackoverflow.com/questions/37131278/how-to-make-the-blur-effect-with-react-native
10+
*
11+
* @param widget
12+
* @param child_composer
13+
* @returns
14+
*/
515
export function compose_wrapped_with_blurred(
616
widget: core.Blurred,
717
child_composer: Composer
@@ -10,12 +20,14 @@ export function compose_wrapped_with_blurred(
1020
const isBlurVisibile = widget.blur.visible;
1121
if (isBlurVisibile) {
1222
if (widget.blur.type === "LAYER_BLUR") {
13-
child.extendStyle({
14-
filter: css.blur(widget.blur.radius),
23+
child.extendStyle<ViewStyle>({
24+
// FIXME: blur not supported in RN
25+
// filter: css.blur(widget.blur.radius),
1526
});
1627
} else if (widget.blur.type === "BACKGROUND_BLUR") {
17-
child.extendStyle({
18-
"backdrop-filter": css.blur(widget.blur.radius),
28+
child.extendStyle<ViewStyle>({
29+
// FIXME: backdrop-filter not supported in RN
30+
// "backdrop-filter": css.blur(widget.blur.radius),
1931
});
2032
}
2133
}

packages/designto-react-native/tokens-to-rn-widget/compose-wrapped-with-opacity.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import * as core from "@reflect-ui/core";
22
import { Composer } from ".";
33
import * as css from "@web-builder/styles";
4+
import type { ViewStyle } from "react-native";
45

56
export function compose_wrapped_with_opacity(
67
widget: core.Opacity,
78
child_composer: Composer
89
) {
910
const child = child_composer(widget.child);
10-
child.extendStyle({
11+
child.extendStyle<ViewStyle>({
1112
opacity: css.opacity(widget.opacity),
1213
});
1314
return child;

packages/designto-react-native/tokens-to-rn-widget/compose-wrapped-with-overflow-box.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import * as core from "@reflect-ui/core";
22
import { Composer } from ".";
3+
import type { ViewStyle } from "react-native";
34

45
export function compose_wrapped_with_overflow_box(
56
widget: core.OverflowBox,
67
child_composer: Composer
78
) {
89
const child = child_composer(widget.child);
9-
child.extendStyle({
10+
child.extendStyle<ViewStyle>({
1011
overflow: "hidden",
1112
});
1213
return child;

packages/designto-react-native/tokens-to-rn-widget/compose-wrapped-with-positioned.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as core from "@reflect-ui/core";
22
import { Composer } from ".";
33
import * as css from "@web-builder/styles";
4+
import type { ViewStyle } from "react-native";
45

56
export function compose_wrapped_with_positioned(
67
widget: core.Positioned,
@@ -9,7 +10,7 @@ export function compose_wrapped_with_positioned(
910
const child = child_composer(widget.child);
1011
// -------------------------------------
1112
// override w & h with position provided w/h
12-
child.extendStyle({
13+
child.extendStyle<ViewStyle>({
1314
width: css.length(widget.width),
1415
height: css.length(widget.height),
1516
});
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import * as core from "@reflect-ui/core";
22
import { Composer } from ".";
3-
import * as css from "@web-builder/styles";
3+
import type { ViewStyle } from "react-native";
44

55
export function compose_wrapped_with_rotation(
66
widget: core.Rotation,
77
child_composer: Composer
88
) {
99
const child = child_composer(widget.child);
10-
child.extendStyle({
11-
transform: css.rotation(widget.rotation),
10+
child.extendStyle<ViewStyle>({
11+
transform: [
12+
{
13+
rotate: `${widget.rotation}deg`,
14+
},
15+
],
1216
});
1317
return child;
1418
}

packages/designto-react-native/tokens-to-rn-widget/compose-wrapped-with-sized-box.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import * as core from "@reflect-ui/core";
22
import { Composer } from ".";
33
import * as css from "@web-builder/styles";
4+
import type { ViewStyle } from "react-native";
45

56
export function compose_wrapped_with_sized_box(
67
widget: core.SizedBox,
78
child_composer: Composer
89
) {
910
const child = child_composer(widget.child);
10-
child.extendStyle({
11+
child.extendStyle<ViewStyle>({
1112
width: css.px(widget.width),
1213
height: css.px(widget.height),
1314
});

packages/designto-react-native/tokens-to-rn-widget/compose-wrapped-with-stretched.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as core from "@reflect-ui/core";
22
import { Composer } from ".";
33
import { Stretched } from "@designto/token/tokens";
4+
import type { ViewStyle } from "react-native";
45

56
export function compose_wrapped_with_clip_stretched(
67
widget: Stretched,
@@ -17,8 +18,8 @@ export function compose_wrapped_with_clip_stretched(
1718
}
1819

1920
const child = child_composer(widget.child);
20-
child.extendStyle({
21-
"align-self": "stretch",
21+
child.extendStyle<ViewStyle>({
22+
alignSelf: "stretch",
2223
[remove_size]: undefined,
2324
});
2425
return child;

0 commit comments

Comments
 (0)