@builder.io/sdk-react-native 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,6 +32,7 @@ const device_sizes_js_1 = require("../../constants/device-sizes.js");
32
32
  const target_js_1 = require("../../constants/target.js");
33
33
  const get_processed_block_js_1 = require("../../functions/get-processed-block.js");
34
34
  const css_js_1 = require("../../helpers/css.js");
35
+ const nullable_js_1 = require("../../helpers/nullable.js");
35
36
  const render_inlined_styles_1 = __importDefault(require("../render-inlined-styles"));
36
37
  function BlockStyles(props) {
37
38
  function useBlock() {
@@ -42,6 +43,16 @@ function BlockStyles(props) {
42
43
  shouldEvaluateBindings: true,
43
44
  });
44
45
  }
46
+ function canShowBlock() {
47
+ // only render styles for blocks that are visible
48
+ if ((0, nullable_js_1.checkIsDefined)(useBlock().hide)) {
49
+ return !useBlock().hide;
50
+ }
51
+ if ((0, nullable_js_1.checkIsDefined)(useBlock().show)) {
52
+ return useBlock().show;
53
+ }
54
+ return true;
55
+ }
45
56
  function css() {
46
57
  var _a;
47
58
  const styles = useBlock().responsiveStyles;
@@ -73,7 +84,7 @@ function BlockStyles(props) {
73
84
  : "";
74
85
  return [largeStylesClass, mediumStylesClass, smallStylesClass].join(" ");
75
86
  }
76
- return (React.createElement(React.Fragment, null, target_js_1.TARGET !== "reactNative" && css() ? (React.createElement(React.Fragment, null,
87
+ return (React.createElement(React.Fragment, null, target_js_1.TARGET !== "reactNative" && css() && canShowBlock() ? (React.createElement(React.Fragment, null,
77
88
  React.createElement(render_inlined_styles_1.default, { styles: css() }))) : null));
78
89
  }
79
90
  exports.default = BlockStyles;
@@ -41,6 +41,7 @@ const target_js_1 = require("../../constants/target.js");
41
41
  const extract_text_styles_js_1 = require("../../functions/extract-text-styles.js");
42
42
  const render_component_1 = __importDefault(require("./render-component"));
43
43
  const get_react_native_block_styles_js_1 = require("../../functions/get-react-native-block-styles.js");
44
+ const nullable_js_1 = require("../../helpers/nullable.js");
44
45
  function RenderBlock(props) {
45
46
  var _a, _b;
46
47
  const [component, setComponent] = (0, react_1.useState)(() => (0, render_block_helpers_js_1.getComponent)({
@@ -60,6 +61,15 @@ function RenderBlock(props) {
60
61
  shouldEvaluateBindings: true,
61
62
  });
62
63
  }
64
+ function canShowBlock() {
65
+ if ((0, nullable_js_1.checkIsDefined)(useBlock().hide)) {
66
+ return !useBlock().hide;
67
+ }
68
+ if ((0, nullable_js_1.checkIsDefined)(useBlock().show)) {
69
+ return useBlock().show;
70
+ }
71
+ return true;
72
+ }
63
73
  function proxyState() {
64
74
  if (typeof Proxy === "undefined") {
65
75
  console.error("no Proxy available in this environment, cannot proxy state.");
@@ -158,7 +168,7 @@ function RenderBlock(props) {
158
168
  inheritedStyles: getInheritedTextStyles(),
159
169
  };
160
170
  }
161
- return (React.createElement(React.Fragment, null, !(component === null || component === void 0 ? void 0 : component.noWrap) ? (React.createElement(React.Fragment, null,
171
+ return (React.createElement(React.Fragment, null, canShowBlock() ? (React.createElement(React.Fragment, null, !(component === null || component === void 0 ? void 0 : component.noWrap) ? (React.createElement(React.Fragment, null,
162
172
  (0, render_block_helpers_js_1.isEmptyHtmlElement)(tag()) ? (React.createElement(React.Fragment, null,
163
173
  React.createElement(react_native_1.View, { ...attributes(), ...actions() }))) : null,
164
174
  !(0, render_block_helpers_js_1.isEmptyHtmlElement)(tag()) && repeatItemData ? (React.createElement(React.Fragment, null, repeatItemData === null || repeatItemData === void 0 ? void 0 : repeatItemData.map((data, index) => (React.createElement(render_repeated_block_1.default, { key: index, repeatContext: data.context, block: data.block }))))) : null,
@@ -166,6 +176,6 @@ function RenderBlock(props) {
166
176
  React.createElement(react_native_1.View, { ...attributes(), ...actions() },
167
177
  React.createElement(render_component_1.default, { ...renderComponentProps() }), (_a = childrenWithoutParentComponent()) === null || _a === void 0 ? void 0 :
168
178
  _a.map((child) => (React.createElement(RenderBlock, { key: "render-block-" + child.id, block: child, context: childrenContext() }))), (_b = childrenWithoutParentComponent()) === null || _b === void 0 ? void 0 :
169
- _b.map((child) => (React.createElement(block_styles_1.default, { key: "block-style-" + child.id, block: child, context: childrenContext() })))))) : null)) : (React.createElement(render_component_1.default, { ...renderComponentProps() }))));
179
+ _b.map((child) => (React.createElement(block_styles_1.default, { key: "block-style-" + child.id, block: child, context: childrenContext() })))))) : null)) : (React.createElement(render_component_1.default, { ...renderComponentProps() })))) : null));
170
180
  }
171
181
  exports.default = RenderBlock;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-react-native",
3
3
  "description": "Builder.io SDK for React Native",
4
- "version": "0.1.7",
4
+ "version": "0.1.8",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
@@ -31,7 +31,6 @@
31
31
  "devDependencies": {
32
32
  "@tsconfig/react-native": "^2.0.3",
33
33
  "@types/react-native-video": "^5.0.9",
34
- "react-native": "^0.64.3",
35
34
  "react-native-url-polyfill": "^1.3.0",
36
35
  "typescript": "^4.9.4"
37
36
  }
@@ -7,6 +7,7 @@ import {
7
7
  import { TARGET } from "../../constants/target.js";
8
8
  import { getProcessedBlock } from "../../functions/get-processed-block.js";
9
9
  import { createCssClass } from "../../helpers/css.js";
10
+ import { checkIsDefined } from "../../helpers/nullable.js";
10
11
  import RenderInlinedStyles from "../render-inlined-styles";
11
12
 
12
13
  export default function BlockStyles(props) {
@@ -19,6 +20,17 @@ export default function BlockStyles(props) {
19
20
  });
20
21
  }
21
22
 
23
+ function canShowBlock() {
24
+ // only render styles for blocks that are visible
25
+ if (checkIsDefined(useBlock().hide)) {
26
+ return !useBlock().hide;
27
+ }
28
+ if (checkIsDefined(useBlock().show)) {
29
+ return useBlock().show;
30
+ }
31
+ return true;
32
+ }
33
+
22
34
  function css() {
23
35
  const styles = useBlock().responsiveStyles;
24
36
  const content = props.context.content;
@@ -60,7 +72,7 @@ export default function BlockStyles(props) {
60
72
 
61
73
  return (
62
74
  <>
63
- {TARGET !== "reactNative" && css() ? (
75
+ {TARGET !== "reactNative" && css() && canShowBlock() ? (
64
76
  <>
65
77
  <RenderInlinedStyles styles={css()} />
66
78
  </>
@@ -17,6 +17,7 @@ import { TARGET } from "../../constants/target.js";
17
17
  import { extractTextStyles } from "../../functions/extract-text-styles.js";
18
18
  import RenderComponent from "./render-component";
19
19
  import { getReactNativeBlockStyles } from "../../functions/get-react-native-block-styles.js";
20
+ import { checkIsDefined } from "../../helpers/nullable.js";
20
21
 
21
22
  export default function RenderBlock(props) {
22
23
  const [component, setComponent] = useState(() =>
@@ -41,6 +42,16 @@ export default function RenderBlock(props) {
41
42
  });
42
43
  }
43
44
 
45
+ function canShowBlock() {
46
+ if (checkIsDefined(useBlock().hide)) {
47
+ return !useBlock().hide;
48
+ }
49
+ if (checkIsDefined(useBlock().show)) {
50
+ return useBlock().show;
51
+ }
52
+ return true;
53
+ }
54
+
44
55
  function proxyState() {
45
56
  if (typeof Proxy === "undefined") {
46
57
  console.error(
@@ -153,51 +164,55 @@ export default function RenderBlock(props) {
153
164
 
154
165
  return (
155
166
  <>
156
- {!component?.noWrap ? (
167
+ {canShowBlock() ? (
157
168
  <>
158
- {isEmptyHtmlElement(tag()) ? (
159
- <>
160
- <View {...attributes()} {...actions()} />
161
- </>
162
- ) : null}
163
- {!isEmptyHtmlElement(tag()) && repeatItemData ? (
164
- <>
165
- {repeatItemData?.map((data, index) => (
166
- <RenderRepeatedBlock
167
- key={index}
168
- repeatContext={data.context}
169
- block={data.block}
170
- />
171
- ))}
172
- </>
173
- ) : null}
174
- {!isEmptyHtmlElement(tag()) && !repeatItemData ? (
169
+ {!component?.noWrap ? (
175
170
  <>
176
- <View {...attributes()} {...actions()}>
177
- <RenderComponent {...renderComponentProps()} />
171
+ {isEmptyHtmlElement(tag()) ? (
172
+ <>
173
+ <View {...attributes()} {...actions()} />
174
+ </>
175
+ ) : null}
176
+ {!isEmptyHtmlElement(tag()) && repeatItemData ? (
177
+ <>
178
+ {repeatItemData?.map((data, index) => (
179
+ <RenderRepeatedBlock
180
+ key={index}
181
+ repeatContext={data.context}
182
+ block={data.block}
183
+ />
184
+ ))}
185
+ </>
186
+ ) : null}
187
+ {!isEmptyHtmlElement(tag()) && !repeatItemData ? (
188
+ <>
189
+ <View {...attributes()} {...actions()}>
190
+ <RenderComponent {...renderComponentProps()} />
178
191
 
179
- {childrenWithoutParentComponent()?.map((child) => (
180
- <RenderBlock
181
- key={"render-block-" + child.id}
182
- block={child}
183
- context={childrenContext()}
184
- />
185
- ))}
192
+ {childrenWithoutParentComponent()?.map((child) => (
193
+ <RenderBlock
194
+ key={"render-block-" + child.id}
195
+ block={child}
196
+ context={childrenContext()}
197
+ />
198
+ ))}
186
199
 
187
- {childrenWithoutParentComponent()?.map((child) => (
188
- <BlockStyles
189
- key={"block-style-" + child.id}
190
- block={child}
191
- context={childrenContext()}
192
- />
193
- ))}
194
- </View>
200
+ {childrenWithoutParentComponent()?.map((child) => (
201
+ <BlockStyles
202
+ key={"block-style-" + child.id}
203
+ block={child}
204
+ context={childrenContext()}
205
+ />
206
+ ))}
207
+ </View>
208
+ </>
209
+ ) : null}
195
210
  </>
196
- ) : null}
211
+ ) : (
212
+ <RenderComponent {...renderComponentProps()} />
213
+ )}
197
214
  </>
198
- ) : (
199
- <RenderComponent {...renderComponentProps()} />
200
- )}
215
+ ) : null}
201
216
  </>
202
217
  );
203
218
  }