Skip to content

Commit f1c5bc0

Browse files
authored
Multiple minor changes (#717)
* Update incosisten reanimated version * Added seperate pause/play to media components * Extract children if in fragment to ensure type check is valid * Add 'initialTabIndex' prop to TabView * v48.2.3
1 parent 82cfc44 commit f1c5bc0

File tree

17 files changed

+141
-42
lines changed

17 files changed

+141
-42
lines changed

example/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@draftbit/example",
33
"description": "Example app for @draftbit/ui",
4-
"version": "48.2.2",
4+
"version": "48.2.3",
55
"private": true,
66
"main": "__generated__/AppEntry.js",
77
"scripts": {
@@ -16,8 +16,8 @@
1616
"clean:modules": "rimraf node_modules"
1717
},
1818
"dependencies": {
19-
"@draftbit/maps": "48.2.2",
20-
"@draftbit/ui": "48.2.2",
19+
"@draftbit/maps": "48.2.3",
20+
"@draftbit/ui": "48.2.3",
2121
"@expo/dev-server": "0.1.123",
2222
"@expo/webpack-config": "^18.0.1",
2323
"@react-navigation/drawer": "^5.12.9",

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "48.2.2",
2+
"version": "48.2.3",
33
"npmClient": "yarn",
44
"useWorkspaces": true,
55
"packages": ["packages/*", "example"],

packages/core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@draftbit/core",
3-
"version": "48.2.2",
3+
"version": "48.2.3",
44
"description": "Core (non-native) Components",
55
"main": "lib/commonjs/index.js",
66
"types": "lib/typescript/src/index.d.ts",
@@ -41,7 +41,7 @@
4141
"dependencies": {
4242
"@date-io/date-fns": "^1.3.13",
4343
"@draftbit/react-theme-provider": "^2.1.1",
44-
"@draftbit/types": "48.2.2",
44+
"@draftbit/types": "48.2.3",
4545
"@expo/vector-icons": "^13.0.0",
4646
"@material-ui/core": "^4.11.0",
4747
"@material-ui/pickers": "^3.2.10",

packages/core/src/__tests__/components/AudioPlayer.test.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,30 @@ describe("AudioPlayer tests", () => {
153153
expect(mockPauseAsync).toBeCalled();
154154
});
155155

156+
test("should play() play the audio", async () => {
157+
const ref = React.createRef<AudioPlayerRef>();
158+
159+
render(<AudioPlayer ref={ref} source={mockAudioSource} />);
160+
161+
await act(async () => {
162+
await waitForSoundToLoad();
163+
ref.current?.play();
164+
});
165+
expect(mockPlayAsync).toBeCalled();
166+
});
167+
168+
test("should pause() pause the audio", async () => {
169+
const ref = React.createRef<AudioPlayerRef>();
170+
171+
render(<AudioPlayer ref={ref} source={mockAudioSource} />);
172+
173+
await act(async () => {
174+
await waitForSoundToLoad();
175+
ref.current?.pause();
176+
});
177+
expect(mockPauseAsync).toBeCalled();
178+
});
179+
156180
test("should audio be cleaned up/unloaded when unmounting", async () => {
157181
render(<AudioPlayer source={mockAudioSource} />);
158182

packages/core/src/__tests__/components/VideoPlayer.test.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,42 @@ describe("VideoPlayer tests", () => {
7070
expect(mockPauseAsync).toBeCalled();
7171
});
7272

73+
test("should play() play the video", async () => {
74+
const ref = React.createRef<VideoPlayerRef>();
75+
76+
render(
77+
<VideoPlayer
78+
ref={ref}
79+
source={{
80+
uri: "video-uri",
81+
}}
82+
/>
83+
);
84+
85+
act(() => {
86+
ref.current?.play();
87+
});
88+
expect(mockPlayAsync).toBeCalled();
89+
});
90+
91+
test("should pause() pause the video", async () => {
92+
const ref = React.createRef<VideoPlayerRef>();
93+
94+
render(
95+
<VideoPlayer
96+
ref={ref}
97+
source={{
98+
uri: "video-uri",
99+
}}
100+
/>
101+
);
102+
103+
act(() => {
104+
ref.current?.pause();
105+
});
106+
expect(mockPauseAsync).toBeCalled();
107+
});
108+
73109
test("should video be cleaned up/unloaded when unmounting", async () => {
74110
render(
75111
<VideoPlayer

packages/core/src/components/MediaPlayer/MediaPlaybackWrapper.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ const MediaPlaybackWrapper = React.forwardRef<
2626
}
2727
}, [media, isPlaying, onTogglePlayback]);
2828

29+
const pause = React.useCallback(async () => {
30+
onTogglePlayback?.();
31+
await media?.pauseAsync();
32+
}, [media, onTogglePlayback]);
33+
34+
const play = React.useCallback(async () => {
35+
onTogglePlayback?.();
36+
await media?.playAsync();
37+
}, [media, onTogglePlayback]);
38+
2939
const seekToPosition = React.useCallback(
3040
async (positionMillis: number) => {
3141
await media?.setPositionAsync(positionMillis);
@@ -46,8 +56,10 @@ const MediaPlaybackWrapper = React.forwardRef<
4656
() => ({
4757
seekToPosition,
4858
togglePlayback,
59+
pause,
60+
play,
4961
}),
50-
[seekToPosition, togglePlayback]
62+
[seekToPosition, togglePlayback, pause, play]
5163
);
5264

5365
return <>{children}</>;

packages/core/src/components/MediaPlayer/MediaPlayerCommon.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export interface MediaPlayerStatus {
1414
export interface MediaPlayerRef {
1515
seekToPosition: (positionMillis: number) => void;
1616
togglePlayback: () => void;
17+
pause: () => void;
18+
play: () => void;
1719
}
1820

1921
export interface MediaPlayerProps {

packages/core/src/components/MediaPlayer/VideoPlayer/VideoPlayer.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ const VideoPlayer = React.forwardRef<VideoPlayerRef, VideoPlayerProps>(
105105
mediaPlaybackWrapperRef.current?.seekToPosition || (() => {}),
106106
togglePlayback:
107107
mediaPlaybackWrapperRef.current?.togglePlayback || (() => {}),
108+
pause: mediaPlaybackWrapperRef.current?.pause || (() => {}),
109+
play: mediaPlaybackWrapperRef.current?.play || (() => {}),
108110
}),
109111
// Include 'isPlaying' as dependency because 'togglePlayback' changes when it changes
110112
// eslint-disable-next-line react-hooks/exhaustive-deps

packages/core/src/components/SectionList/SectionList.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from "react";
22
import { FlashListProps, FlashList } from "@shopify/flash-list";
33
import { FlatListProps, FlatList } from "react-native";
44
import SectionHeader, { DefaultSectionHeader } from "./SectionHeader";
5+
import { extractIfNestedInFragment } from "../../utilities";
56

67
type ListComponentType = "FlatList" | "FlashList";
78

@@ -88,9 +89,10 @@ const SectionList = <T extends { [key: string]: any }>({
8889
}
8990

9091
const props = element.props || {};
91-
const children = React.Children.toArray(props.children).map(
92-
(child) => child as React.ReactElement
92+
const children = React.Children.toArray(props.children).map((child) =>
93+
extractIfNestedInFragment(child as React.ReactElement)
9394
);
95+
9496
if (element.type === SectionHeader) {
9597
return element;
9698
} else {

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
extractBorderAndMarginStyles,
1313
extractEffectStyles,
1414
extractFlexItemStyles,
15+
extractIfNestedInFragment,
1516
extractPositionStyles,
1617
extractSizeStyles,
1718
extractStyles,
@@ -74,7 +75,7 @@ type Props = SwipeableItemProps & RightSwipeProps & LeftSwipeProps;
7475
const SwipeableItem: React.FC<React.PropsWithChildren<Props>> = ({
7576
theme,
7677
style,
77-
children,
78+
children: childrenProp,
7879
Icon,
7980
closeOnPress,
8081
leftOpenValue,
@@ -124,9 +125,18 @@ const SwipeableItem: React.FC<React.PropsWithChildren<Props>> = ({
124125
const [componentWidth, setComponentWidth] = React.useState<number | null>(
125126
null
126127
);
128+
129+
const children: React.ReactNode[] = React.useMemo(
130+
() =>
131+
React.Children.toArray(childrenProp).map((child) =>
132+
extractIfNestedInFragment(child as React.ReactElement)
133+
),
134+
[childrenProp]
135+
);
136+
127137
const leftSwipeButtons = React.useMemo(
128138
() =>
129-
React.Children.toArray(children).filter(
139+
children.filter(
130140
(child) =>
131141
React.isValidElement(child) &&
132142
child.type === SwipeableItemButton &&
@@ -137,7 +147,7 @@ const SwipeableItem: React.FC<React.PropsWithChildren<Props>> = ({
137147

138148
const rightSwipeButtons = React.useMemo(
139149
() =>
140-
React.Children.toArray(children).filter(
150+
children.filter(
141151
(child) =>
142152
React.isValidElement(child) &&
143153
child.type === SwipeableItemButton &&

0 commit comments

Comments
 (0)