Skip to content

Commit dd05212

Browse files
committed
Merge remote-tracking branch 'origin/47' into youssef/p-3546-add-section-list-component47
2 parents f08a9f7 + a7ef8c3 commit dd05212

File tree

8 files changed

+49
-44
lines changed

8 files changed

+49
-44
lines changed

example/src/WebViewExample.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@ const WebViewExample = () => (
1414
/>
1515
</Section>
1616
<Section title="With custom HTML">
17-
<WebView
18-
style={style.webView}
19-
source={{
20-
html: "<div> Hello! </div>",
21-
}}
22-
/>
17+
<WebView style={style.webView} html="<div> Hello! </div>" />
2318
</Section>
2419
</Container>
2520
);

packages/core/src/components/SwipeableItem/SwipeableItem.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ import { SwipeRow } from "react-native-swipe-list-view";
2020
import { IconSlot } from "../../interfaces/Icon";
2121
import type { Theme } from "../../styles/DefaultTheme";
2222
import { withTheme } from "../../theming";
23-
import { SwipeableItemButtonProps } from "./SwipeableItemButton";
23+
import SwipeableItemButton, {
24+
SwipeableItemButtonProps,
25+
} from "./SwipeableItemButton";
2426
import { SwipeableListContext } from "./SwipeableList";
2527
import {
2628
RightSwipeProps,
@@ -87,12 +89,6 @@ const SwipeableItem: React.FC<React.PropsWithChildren<Props>> = ({
8789
disableRightSwipe,
8890
...rest
8991
}) => {
90-
const instanceOfSwipeableItemButtonProps = (
91-
object: any
92-
): object is SwipeableItemButtonProps => {
93-
return "title" in object && "revealSwipeDirection" in object;
94-
};
95-
9692
const isEmptyObject = (object: object) => {
9793
return Object.keys(object).length === 0;
9894
};
@@ -131,7 +127,7 @@ const SwipeableItem: React.FC<React.PropsWithChildren<Props>> = ({
131127
React.Children.toArray(children).filter(
132128
(child) =>
133129
React.isValidElement(child) &&
134-
instanceOfSwipeableItemButtonProps(child.props) &&
130+
child.type === SwipeableItemButton &&
135131
child.props.revealSwipeDirection === "left"
136132
) as React.ReactElement<SwipeableItemButtonProps>[],
137133
[children]
@@ -142,7 +138,7 @@ const SwipeableItem: React.FC<React.PropsWithChildren<Props>> = ({
142138
React.Children.toArray(children).filter(
143139
(child) =>
144140
React.isValidElement(child) &&
145-
instanceOfSwipeableItemButtonProps(child.props) &&
141+
child.type === SwipeableItemButton &&
146142
child.props.revealSwipeDirection === "right"
147143
) as React.ReactElement<SwipeableItemButtonProps>[],
148144
[children]
@@ -152,8 +148,7 @@ const SwipeableItem: React.FC<React.PropsWithChildren<Props>> = ({
152148
() =>
153149
React.Children.toArray(children).filter(
154150
(child) =>
155-
React.isValidElement(child) &&
156-
!instanceOfSwipeableItemButtonProps(child.props)
151+
React.isValidElement(child) && child.type !== SwipeableItemButton
157152
),
158153
[children]
159154
);

packages/core/src/components/TabView/TabView.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
Route,
99
} from "react-native-tab-view";
1010

11-
import { TabViewItemProps } from "./TabViewItem";
11+
import TabViewItem from "./TabViewItem";
1212
import type { IconSlot } from "../../interfaces/Icon";
1313
import { withTheme } from "../../theming";
1414
import type { Theme } from "../../styles/DefaultTheme";
@@ -62,23 +62,14 @@ const TabViewComponent: React.FC<React.PropsWithChildren<TabViewProps>> = ({
6262

6363
const { textStyles, viewStyles } = extractStyles(style);
6464

65-
//Check type of child using props
66-
//Regular '.type' cannot work because Draftbit strips the type in Draft view
67-
const instanceOfTabViewItemProps = (
68-
object: any
69-
): object is TabViewItemProps => {
70-
return "title" in object;
71-
};
72-
7365
//Populate routes and scenes based on children
7466
React.useEffect(() => {
7567
const newRoutes: Route[] = [];
7668
const scenes: { [key: string]: React.ReactElement } = {};
7769

7870
React.Children.toArray(children)
7971
.filter(
80-
(child) =>
81-
React.isValidElement(child) && instanceOfTabViewItemProps(child.props)
72+
(child) => React.isValidElement(child) && child.type === TabViewItem
8273
)
8374
.forEach((item: any, idx) => {
8475
const child = item as React.ReactElement;

packages/core/src/components/TabView/TabViewItem.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from "react";
22
import { StyleProp, ViewStyle, StyleSheet, View } from "react-native";
33

4-
//Props used by parent (TabView) to create tabs
5-
export interface TabViewItemProps {
4+
interface TabViewItemProps {
65
title: string;
76
icon?: string;
87
accessibilityLabel?: string;

packages/core/src/components/Table/TableCell.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import {
55
TableProps,
66
TableStyleContext,
77
} from "./TableCommon";
8+
import Pressable from "../Pressable";
89

910
export interface Props extends TableProps {
11+
onPress?: () => void;
1012
style?: StyleProp<ViewStyle>;
1113
}
1214

@@ -21,6 +23,7 @@ const TableCell: React.FC<React.PropsWithChildren<Props>> = ({
2123
cellVerticalPadding,
2224
cellHorizontalPadding,
2325
children,
26+
onPress,
2427
style,
2528
}) => {
2629
const parentContextValue = React.useContext(TableStyleContext);
@@ -34,8 +37,11 @@ const TableCell: React.FC<React.PropsWithChildren<Props>> = ({
3437
drawStartBorder,
3538
drawEndBorder,
3639
});
40+
41+
const ContainerComponent = onPress ? Pressable : View;
3742
return (
38-
<View
43+
<ContainerComponent
44+
onPress={onPress}
3945
style={[
4046
styles.cellContainer,
4147
borderViewStyle,
@@ -49,7 +55,7 @@ const TableCell: React.FC<React.PropsWithChildren<Props>> = ({
4955
]}
5056
>
5157
{children}
52-
</View>
58+
</ContainerComponent>
5359
);
5460
};
5561

packages/core/src/components/Table/TableRow.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import {
88
} from "./TableCommon";
99
import { Theme } from "../../styles/DefaultTheme";
1010
import { withTheme } from "../../theming";
11+
import Pressable from "../Pressable";
1112

1213
export interface Props extends TableProps {
14+
onPress?: () => void;
1315
isTableHeader?: boolean;
1416
style?: StyleProp<ViewStyle>;
1517
theme: Theme;
@@ -27,6 +29,7 @@ const TableRow: React.FC<React.PropsWithChildren<Props>> = ({
2729
cellHorizontalPadding,
2830
isTableHeader = false,
2931
children,
32+
onPress,
3033
style,
3134
theme,
3235
}) => {
@@ -52,9 +55,12 @@ const TableRow: React.FC<React.PropsWithChildren<Props>> = ({
5255
drawStartBorder,
5356
drawEndBorder,
5457
});
58+
59+
const ContainerComponent = onPress ? Pressable : View;
5560
return (
5661
<TableStyleContext.Provider value={contextValue}>
57-
<View
62+
<ContainerComponent
63+
onPress={onPress}
5864
style={[
5965
borderViewStyle,
6066
isTableHeader ? { backgroundColor: theme.colors.primary } : {},
@@ -63,7 +69,7 @@ const TableRow: React.FC<React.PropsWithChildren<Props>> = ({
6369
]}
6470
>
6571
{children}
66-
</View>
72+
</ContainerComponent>
6773
</TableStyleContext.Provider>
6874
);
6975
};

packages/maps/src/components/MapMarker.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ export function renderMarker(
5757
if (calloutChildren.length === 0 && (title || description)) {
5858
calloutChildren.push(
5959
<MapCallout showTooltip>
60-
<View>
61-
{title && <Text style={style.title}>{title}</Text>}
62-
{description && <Text style={style.description}>{description}</Text>}
60+
<View style={styles.defaultCalloutContainer}>
61+
{title && <Text style={styles.defaultCalloutTitle}>{title}</Text>}
62+
{description && (
63+
<Text style={styles.defaultCalloutDescription}>{description}</Text>
64+
)}
6365
</View>
6466
</MapCallout>
6567
);
@@ -98,13 +100,17 @@ export function renderMarker(
98100
);
99101
}
100102

101-
const style = StyleSheet.create({
102-
title: {
103+
const styles = StyleSheet.create({
104+
defaultCalloutContainer: {
105+
flex: 1,
106+
},
107+
defaultCalloutTitle: {
103108
fontWeight: "600",
104109
textAlign: "center",
110+
maxWidth: 250,
105111
},
106-
description: {
107-
textAlign: "center",
112+
defaultCalloutDescription: {
113+
maxWidth: 250,
108114
},
109115
});
110116

packages/native/src/components/WebView.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ const injectFirst = `
3939
`;
4040

4141
interface WebViewProps {
42-
source: WebViewSourceUri | WebViewSourceHtml;
42+
source?: WebViewSourceUri | WebViewSourceHtml;
43+
html?: string;
4344
style?: ViewStyle;
4445
optimizeVideoChat?: boolean;
4546
// Advancted Builder Config Props
@@ -80,7 +81,7 @@ interface WebViewProps {
8081
}
8182

8283
const NativeWebView = React.forwardRef<any, WebViewProps>(
83-
({ source, style, optimizeVideoChat, ...otherWebViewProps }, ref) => {
84+
({ source, html, style, optimizeVideoChat, ...otherWebViewProps }, ref) => {
8485
const [height, setHeight] = useState(0);
8586

8687
const [cameraPermissions, setCameraPermissions] =
@@ -149,6 +150,12 @@ const NativeWebView = React.forwardRef<any, WebViewProps>(
149150
}
150151
};
151152

153+
if (!source && !html) {
154+
throw new Error(
155+
"'source' or 'html' props need to be provided to render WebView"
156+
);
157+
}
158+
152159
const selectComponent = () => {
153160
if (
154161
!optimizeVideoChat ||
@@ -157,7 +164,7 @@ const NativeWebView = React.forwardRef<any, WebViewProps>(
157164
return (
158165
<WebView
159166
ref={ref}
160-
source={source}
167+
source={source || { html: html!! }}
161168
style={{ ...style, width: getFinalWidth() }}
162169
injectedJavaScript={injectFirst}
163170
onMessage={onMessage}

0 commit comments

Comments
 (0)