Skip to content

Commit 561a806

Browse files
authored
Updated how children types is checked + small fix to MapCallout (47) (#690)
* Fixed default Map callout size being too small * Updated how type of children components is checked
1 parent 4af675c commit 561a806

File tree

4 files changed

+22
-31
lines changed

4 files changed

+22
-31
lines changed

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/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

0 commit comments

Comments
 (0)