@draftbit/core 48.1.1-157a30.2 → 48.1.1-2e0561.2
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.
- package/lib/src/components/MediaPlayer/AudioPlayer/AudioPlayerCommon.d.ts +22 -0
- package/lib/src/components/MediaPlayer/AudioPlayer/AudioPlayerCommon.js.map +1 -0
- package/lib/src/components/MediaPlayer/AudioPlayer/AudioPlayerWithInterface.d.ts +7 -0
- package/lib/src/components/{AudioPlayer → MediaPlayer/AudioPlayer}/AudioPlayerWithInterface.js +6 -6
- package/lib/src/components/MediaPlayer/AudioPlayer/AudioPlayerWithInterface.js.map +1 -0
- package/lib/src/components/{AudioPlayer → MediaPlayer/AudioPlayer}/HeadlessAudioPlayer.d.ts +3 -2
- package/lib/src/components/{AudioPlayer → MediaPlayer/AudioPlayer}/HeadlessAudioPlayer.js +9 -48
- package/lib/src/components/MediaPlayer/AudioPlayer/HeadlessAudioPlayer.js.map +1 -0
- package/lib/src/components/{AudioPlayer → MediaPlayer/AudioPlayer}/index.d.ts +5 -4
- package/{src/components → lib/src/components/MediaPlayer}/AudioPlayer/index.js +1 -1
- package/lib/src/components/MediaPlayer/AudioPlayer/index.js.map +1 -0
- package/lib/src/components/MediaPlayer/MediaPlaybackWrapper.d.ts +15 -0
- package/lib/src/components/MediaPlayer/MediaPlaybackWrapper.js +32 -0
- package/lib/src/components/MediaPlayer/MediaPlaybackWrapper.js.map +1 -0
- package/lib/src/components/MediaPlayer/MediaPlayerCommon.d.ts +21 -0
- package/lib/src/components/MediaPlayer/MediaPlayerCommon.js +24 -0
- package/lib/src/components/MediaPlayer/MediaPlayerCommon.js.map +1 -0
- package/lib/src/components/MediaPlayer/VideoPlayer/VideoPlayer.d.ts +15 -0
- package/lib/src/components/MediaPlayer/VideoPlayer/VideoPlayer.js +73 -0
- package/lib/src/components/MediaPlayer/VideoPlayer/VideoPlayer.js.map +1 -0
- package/lib/src/components/MediaPlayer/VideoPlayer/index.d.ts +2 -0
- package/lib/src/components/MediaPlayer/VideoPlayer/index.js +2 -0
- package/lib/src/components/MediaPlayer/VideoPlayer/index.js.map +1 -0
- package/lib/src/components/NumberInput.d.ts +5 -3
- package/lib/src/components/NumberInput.js +13 -3
- package/lib/src/components/NumberInput.js.map +1 -1
- package/lib/src/components/Progress/CircularProgress/CircularProgress.d.ts +6 -0
- package/lib/src/components/Progress/CircularProgress/CircularProgress.js +101 -0
- package/lib/src/components/Progress/CircularProgress/CircularProgress.js.map +1 -0
- package/lib/src/components/Progress/CircularProgress/index.d.ts +6 -0
- package/lib/src/components/Progress/CircularProgress/index.js +14 -0
- package/lib/src/components/Progress/CircularProgress/index.js.map +1 -0
- package/lib/src/components/Progress/IndeterminateProgress.d.ts +7 -0
- package/lib/src/components/Progress/IndeterminateProgress.js +39 -0
- package/lib/src/components/Progress/IndeterminateProgress.js.map +1 -0
- package/lib/src/components/Progress/LinearProgress/LinearProgress.d.ts +6 -0
- package/lib/src/components/Progress/LinearProgress/LinearProgress.js +54 -0
- package/lib/src/components/Progress/LinearProgress/LinearProgress.js.map +1 -0
- package/lib/src/components/Progress/LinearProgress/index.d.ts +6 -0
- package/lib/src/components/Progress/LinearProgress/index.js +14 -0
- package/lib/src/components/Progress/LinearProgress/index.js.map +1 -0
- package/lib/src/components/Progress/ProgressCommon.d.ts +40 -0
- package/lib/src/components/Progress/ProgressCommon.js +2 -0
- package/lib/src/components/Progress/ProgressCommon.js.map +1 -0
- package/lib/src/components/SwipeableItem/SwipeableItem.js +9 -2
- package/lib/src/components/SwipeableItem/SwipeableItem.js.map +1 -1
- package/lib/src/components/SwipeableItem/SwipeableItemCommon.d.ts +3 -2
- package/lib/src/components/SwipeableItem/SwipeableItemCommon.js.map +1 -1
- package/lib/src/components/TextField.d.ts +2 -1
- package/lib/src/components/TextField.js +3 -2
- package/lib/src/components/TextField.js.map +1 -1
- package/lib/src/components/TextInput.d.ts +8 -0
- package/lib/src/components/TextInput.js +15 -0
- package/lib/src/components/TextInput.js.map +1 -0
- package/lib/src/hooks.d.ts +1 -0
- package/lib/src/hooks.js +12 -0
- package/lib/src/hooks.js.map +1 -1
- package/lib/src/index.d.ts +5 -1
- package/lib/src/index.js +5 -1
- package/lib/src/index.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -10
- package/src/components/MediaPlayer/AudioPlayer/AudioPlayerCommon.ts +25 -0
- package/src/components/{AudioPlayer → MediaPlayer/AudioPlayer}/AudioPlayerWithInterface.js +6 -6
- package/src/components/MediaPlayer/AudioPlayer/AudioPlayerWithInterface.js.map +1 -0
- package/src/components/{AudioPlayer → MediaPlayer/AudioPlayer}/AudioPlayerWithInterface.tsx +11 -9
- package/src/components/{AudioPlayer → MediaPlayer/AudioPlayer}/HeadlessAudioPlayer.js +9 -48
- package/src/components/MediaPlayer/AudioPlayer/HeadlessAudioPlayer.js.map +1 -0
- package/src/components/{AudioPlayer → MediaPlayer/AudioPlayer}/HeadlessAudioPlayer.tsx +19 -64
- package/{lib/src/components → src/components/MediaPlayer}/AudioPlayer/index.js +1 -1
- package/src/components/MediaPlayer/AudioPlayer/index.js.map +1 -0
- package/src/components/{AudioPlayer → MediaPlayer/AudioPlayer}/index.tsx +4 -4
- package/src/components/MediaPlayer/MediaPlaybackWrapper.js +32 -0
- package/src/components/MediaPlayer/MediaPlaybackWrapper.js.map +1 -0
- package/src/components/MediaPlayer/MediaPlaybackWrapper.tsx +56 -0
- package/src/components/MediaPlayer/MediaPlayerCommon.js +24 -0
- package/src/components/MediaPlayer/MediaPlayerCommon.js.map +1 -0
- package/src/components/MediaPlayer/MediaPlayerCommon.ts +50 -0
- package/src/components/MediaPlayer/VideoPlayer/VideoPlayer.js +73 -0
- package/src/components/MediaPlayer/VideoPlayer/VideoPlayer.js.map +1 -0
- package/src/components/MediaPlayer/VideoPlayer/VideoPlayer.tsx +136 -0
- package/src/components/MediaPlayer/VideoPlayer/index.js +2 -0
- package/src/components/MediaPlayer/VideoPlayer/index.js.map +1 -0
- package/src/components/MediaPlayer/VideoPlayer/index.ts +2 -0
- package/src/components/NumberInput.js +13 -3
- package/src/components/NumberInput.js.map +1 -1
- package/src/components/NumberInput.tsx +34 -5
- package/src/components/Progress/CircularProgress/CircularProgress.js +101 -0
- package/src/components/Progress/CircularProgress/CircularProgress.js.map +1 -0
- package/src/components/Progress/CircularProgress/CircularProgress.tsx +200 -0
- package/src/components/Progress/CircularProgress/index.js +14 -0
- package/src/components/Progress/CircularProgress/index.js.map +1 -0
- package/src/components/Progress/CircularProgress/index.tsx +28 -0
- package/src/components/Progress/IndeterminateProgress.js +39 -0
- package/src/components/Progress/IndeterminateProgress.js.map +1 -0
- package/src/components/Progress/IndeterminateProgress.tsx +74 -0
- package/src/components/Progress/LinearProgress/LinearProgress.js +54 -0
- package/src/components/Progress/LinearProgress/LinearProgress.js.map +1 -0
- package/src/components/Progress/LinearProgress/LinearProgress.tsx +132 -0
- package/src/components/Progress/LinearProgress/index.js +14 -0
- package/src/components/Progress/LinearProgress/index.js.map +1 -0
- package/src/components/Progress/LinearProgress/index.tsx +25 -0
- package/src/components/Progress/ProgressCommon.js +2 -0
- package/src/components/Progress/ProgressCommon.js.map +1 -0
- package/src/components/Progress/ProgressCommon.ts +44 -0
- package/src/components/SwipeableItem/SwipeableItem.js +9 -2
- package/src/components/SwipeableItem/SwipeableItem.js.map +1 -1
- package/src/components/SwipeableItem/SwipeableItem.tsx +9 -1
- package/src/components/SwipeableItem/SwipeableItemCommon.js.map +1 -1
- package/src/components/SwipeableItem/SwipeableItemCommon.ts +3 -2
- package/src/components/TextField.js +3 -2
- package/src/components/TextField.js.map +1 -1
- package/src/components/TextField.tsx +2 -2
- package/src/components/TextInput.js +15 -0
- package/src/components/TextInput.js.map +1 -0
- package/src/components/TextInput.tsx +35 -0
- package/src/hooks.js +12 -0
- package/src/hooks.js.map +1 -1
- package/src/hooks.ts +16 -0
- package/src/index.js +5 -1
- package/src/index.js.map +1 -1
- package/src/index.tsx +8 -1
- package/lib/src/components/AudioPlayer/AudioPlayerCommon.d.ts +0 -39
- package/lib/src/components/AudioPlayer/AudioPlayerCommon.js.map +0 -1
- package/lib/src/components/AudioPlayer/AudioPlayerWithInterface.d.ts +0 -6
- package/lib/src/components/AudioPlayer/AudioPlayerWithInterface.js.map +0 -1
- package/lib/src/components/AudioPlayer/HeadlessAudioPlayer.js.map +0 -1
- package/lib/src/components/AudioPlayer/index.js.map +0 -1
- package/src/components/AudioPlayer/AudioPlayerCommon.ts +0 -44
- package/src/components/AudioPlayer/AudioPlayerWithInterface.js.map +0 -1
- package/src/components/AudioPlayer/HeadlessAudioPlayer.js.map +0 -1
- package/src/components/AudioPlayer/index.js.map +0 -1
- /package/lib/src/components/{AudioPlayer → MediaPlayer/AudioPlayer}/AudioPlayerCommon.js +0 -0
- /package/src/components/{AudioPlayer → MediaPlayer/AudioPlayer}/AudioPlayerCommon.js +0 -0
- /package/src/components/{AudioPlayer → MediaPlayer/AudioPlayer}/AudioPlayerCommon.js.map +0 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Video as VideoPlayerComponent, ResizeMode as ExpoResizeMode, VideoFullscreenUpdate, } from "expo-av";
|
|
3
|
+
import { extractSizeStyles } from "../../../utilities";
|
|
4
|
+
import MediaPlaybackWrapper from "../MediaPlaybackWrapper";
|
|
5
|
+
import { mapToMediaPlayerStatus, } from "../MediaPlayerCommon";
|
|
6
|
+
const VideoPlayer = React.forwardRef(({ style, resizeMode = "contain", posterResizeMode = "cover", onPlaybackStatusUpdate: onPlaybackStatusUpdateProp, onPlaybackFinish, ...rest }, ref) => {
|
|
7
|
+
const [videoMediaObject, setVideoMediaObject] = React.useState();
|
|
8
|
+
const [isPlaying, setIsPlaying] = React.useState(false);
|
|
9
|
+
const [isFullscreen, setIsFullscreen] = React.useState(false);
|
|
10
|
+
const mediaPlaybackWrapperRef = React.useRef(null);
|
|
11
|
+
const sizeStyles = extractSizeStyles(style);
|
|
12
|
+
let mappedResizeMode;
|
|
13
|
+
switch (resizeMode) {
|
|
14
|
+
case "contain":
|
|
15
|
+
mappedResizeMode = ExpoResizeMode.CONTAIN;
|
|
16
|
+
break;
|
|
17
|
+
case "cover":
|
|
18
|
+
mappedResizeMode = ExpoResizeMode.COVER;
|
|
19
|
+
break;
|
|
20
|
+
case "stretch":
|
|
21
|
+
mappedResizeMode = ExpoResizeMode.STRETCH;
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
const onPlaybackStatusUpdate = (status) => {
|
|
25
|
+
const mappedStatus = mapToMediaPlayerStatus(status);
|
|
26
|
+
onPlaybackStatusUpdateProp === null || onPlaybackStatusUpdateProp === void 0 ? void 0 : onPlaybackStatusUpdateProp(mappedStatus);
|
|
27
|
+
if (status.isLoaded) {
|
|
28
|
+
if (status.didJustFinish) {
|
|
29
|
+
onPlaybackFinish === null || onPlaybackFinish === void 0 ? void 0 : onPlaybackFinish();
|
|
30
|
+
}
|
|
31
|
+
setIsPlaying(status.isPlaying);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const onFullscreenUpdate = (fullscreenUpdate) => {
|
|
35
|
+
switch (fullscreenUpdate) {
|
|
36
|
+
case VideoFullscreenUpdate.PLAYER_DID_PRESENT:
|
|
37
|
+
case VideoFullscreenUpdate.PLAYER_WILL_PRESENT:
|
|
38
|
+
setIsFullscreen(true);
|
|
39
|
+
break;
|
|
40
|
+
case VideoFullscreenUpdate.PLAYER_DID_DISMISS:
|
|
41
|
+
case VideoFullscreenUpdate.PLAYER_WILL_DISMISS:
|
|
42
|
+
setIsFullscreen(false);
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const toggleFullscreen = React.useCallback(async () => {
|
|
47
|
+
if (isFullscreen) {
|
|
48
|
+
await (videoMediaObject === null || videoMediaObject === void 0 ? void 0 : videoMediaObject.dismissFullscreenPlayer());
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
await (videoMediaObject === null || videoMediaObject === void 0 ? void 0 : videoMediaObject.presentFullscreenPlayer());
|
|
52
|
+
}
|
|
53
|
+
}, [isFullscreen, videoMediaObject]);
|
|
54
|
+
React.useImperativeHandle(ref, () => {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
return ({
|
|
57
|
+
toggleFullscreen,
|
|
58
|
+
seekToPosition: ((_a = mediaPlaybackWrapperRef.current) === null || _a === void 0 ? void 0 : _a.seekToPosition) || (() => { }),
|
|
59
|
+
togglePlayback: ((_b = mediaPlaybackWrapperRef.current) === null || _b === void 0 ? void 0 : _b.togglePlayback) || (() => { }),
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
// Include 'isPlaying' as dependency because 'togglePlayback' changes when it changes
|
|
63
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
64
|
+
[toggleFullscreen, isPlaying]);
|
|
65
|
+
return (React.createElement(MediaPlaybackWrapper, { media: videoMediaObject, isPlaying: isPlaying, ref: mediaPlaybackWrapperRef },
|
|
66
|
+
React.createElement(VideoPlayerComponent
|
|
67
|
+
// https://docs.expo.dev/versions/latest/sdk/av/#example-video to see why ref is handled this way
|
|
68
|
+
, {
|
|
69
|
+
// https://docs.expo.dev/versions/latest/sdk/av/#example-video to see why ref is handled this way
|
|
70
|
+
ref: (component) => setVideoMediaObject(component), style: style, videoStyle: sizeStyles, resizeMode: mappedResizeMode, posterStyle: [sizeStyles, { resizeMode: posterResizeMode }], onPlaybackStatusUpdate: onPlaybackStatusUpdate, onFullscreenUpdate: (e) => onFullscreenUpdate(e.fullscreenUpdate), ...rest })));
|
|
71
|
+
});
|
|
72
|
+
export default VideoPlayer;
|
|
73
|
+
//# sourceMappingURL=VideoPlayer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VideoPlayer.js","sourceRoot":"","sources":["VideoPlayer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EACL,KAA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E,cAAc,KAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;SAChE,CAAC,CAAA;KAAA;IACF,qFAAqF;IACrF,uDAAuD;IACvD,CAAC,gBAAgB,EAAE,SAAS,CAAC,CAC9B,CAAC;IAEF,OAAO,CACL,oBAAC,oBAAoB,IACnB,KAAK,EAAE,gBAAwC,EAC/C,SAAS,EAAE,SAAS,EACpB,GAAG,EAAE,uBAAuB;QAE5B,oBAAC,oBAAoB;QACnB,iGAAiG;;YAAjG,iGAAiG;YACjG,GAAG,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,mBAAmB,CAAC,SAAS,CAAC,EAClD,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,gBAAgB,EAC5B,WAAW,EAAE,CAAC,UAAU,EAAE,EAAE,UAAU,EAAE,gBAAgB,EAAE,CAAC,EAC3D,sBAAsB,EAAE,sBAAsB,EAC9C,kBAAkB,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,CAAC,CAAC,gBAAgB,CAAC,KAC7D,IAAI,GACR,CACmB,CACxB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ImageResizeMode } from "react-native";
|
|
3
|
+
import {
|
|
4
|
+
Video as VideoPlayerComponent,
|
|
5
|
+
VideoProps as ExpoVideoProps,
|
|
6
|
+
ResizeMode as ExpoResizeMode,
|
|
7
|
+
AVPlaybackStatus,
|
|
8
|
+
VideoFullscreenUpdate,
|
|
9
|
+
} from "expo-av";
|
|
10
|
+
import { extractSizeStyles } from "../../../utilities";
|
|
11
|
+
import MediaPlaybackWrapper from "../MediaPlaybackWrapper";
|
|
12
|
+
import type { Playback } from "expo-av/src/AV";
|
|
13
|
+
import {
|
|
14
|
+
MediaPlayerProps,
|
|
15
|
+
MediaPlayerRef,
|
|
16
|
+
mapToMediaPlayerStatus,
|
|
17
|
+
} from "../MediaPlayerCommon";
|
|
18
|
+
|
|
19
|
+
type ResizeMode = "contain" | "cover" | "stretch";
|
|
20
|
+
type ExpoVideoPropsOmitted = Omit<
|
|
21
|
+
ExpoVideoProps,
|
|
22
|
+
"videoStyle" | "resizeMode" | "onPlaybackStatusUpdate" | "source"
|
|
23
|
+
>;
|
|
24
|
+
|
|
25
|
+
interface VideoPlayerProps extends ExpoVideoPropsOmitted, MediaPlayerProps {
|
|
26
|
+
resizeMode?: ResizeMode;
|
|
27
|
+
posterResizeMode?: ImageResizeMode;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface VideoPlayerRef extends MediaPlayerRef {
|
|
31
|
+
toggleFullscreen: () => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const VideoPlayer = React.forwardRef<VideoPlayerRef, VideoPlayerProps>(
|
|
35
|
+
(
|
|
36
|
+
{
|
|
37
|
+
style,
|
|
38
|
+
resizeMode = "contain",
|
|
39
|
+
posterResizeMode = "cover",
|
|
40
|
+
onPlaybackStatusUpdate: onPlaybackStatusUpdateProp,
|
|
41
|
+
onPlaybackFinish,
|
|
42
|
+
...rest
|
|
43
|
+
},
|
|
44
|
+
ref
|
|
45
|
+
) => {
|
|
46
|
+
const [videoMediaObject, setVideoMediaObject] =
|
|
47
|
+
React.useState<VideoPlayerComponent | null>();
|
|
48
|
+
const [isPlaying, setIsPlaying] = React.useState(false);
|
|
49
|
+
const [isFullscreen, setIsFullscreen] = React.useState(false);
|
|
50
|
+
const mediaPlaybackWrapperRef = React.useRef<MediaPlayerRef>(null);
|
|
51
|
+
|
|
52
|
+
const sizeStyles = extractSizeStyles(style);
|
|
53
|
+
|
|
54
|
+
let mappedResizeMode;
|
|
55
|
+
switch (resizeMode) {
|
|
56
|
+
case "contain":
|
|
57
|
+
mappedResizeMode = ExpoResizeMode.CONTAIN;
|
|
58
|
+
break;
|
|
59
|
+
case "cover":
|
|
60
|
+
mappedResizeMode = ExpoResizeMode.COVER;
|
|
61
|
+
break;
|
|
62
|
+
case "stretch":
|
|
63
|
+
mappedResizeMode = ExpoResizeMode.STRETCH;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const onPlaybackStatusUpdate = (status: AVPlaybackStatus) => {
|
|
68
|
+
const mappedStatus = mapToMediaPlayerStatus(status);
|
|
69
|
+
onPlaybackStatusUpdateProp?.(mappedStatus);
|
|
70
|
+
|
|
71
|
+
if (status.isLoaded) {
|
|
72
|
+
if (status.didJustFinish) {
|
|
73
|
+
onPlaybackFinish?.();
|
|
74
|
+
}
|
|
75
|
+
setIsPlaying(status.isPlaying);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const onFullscreenUpdate = (fullscreenUpdate: VideoFullscreenUpdate) => {
|
|
80
|
+
switch (fullscreenUpdate) {
|
|
81
|
+
case VideoFullscreenUpdate.PLAYER_DID_PRESENT:
|
|
82
|
+
case VideoFullscreenUpdate.PLAYER_WILL_PRESENT:
|
|
83
|
+
setIsFullscreen(true);
|
|
84
|
+
break;
|
|
85
|
+
case VideoFullscreenUpdate.PLAYER_DID_DISMISS:
|
|
86
|
+
case VideoFullscreenUpdate.PLAYER_WILL_DISMISS:
|
|
87
|
+
setIsFullscreen(false);
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const toggleFullscreen = React.useCallback(async () => {
|
|
93
|
+
if (isFullscreen) {
|
|
94
|
+
await videoMediaObject?.dismissFullscreenPlayer();
|
|
95
|
+
} else {
|
|
96
|
+
await videoMediaObject?.presentFullscreenPlayer();
|
|
97
|
+
}
|
|
98
|
+
}, [isFullscreen, videoMediaObject]);
|
|
99
|
+
|
|
100
|
+
React.useImperativeHandle(
|
|
101
|
+
ref,
|
|
102
|
+
() => ({
|
|
103
|
+
toggleFullscreen,
|
|
104
|
+
seekToPosition:
|
|
105
|
+
mediaPlaybackWrapperRef.current?.seekToPosition || (() => {}),
|
|
106
|
+
togglePlayback:
|
|
107
|
+
mediaPlaybackWrapperRef.current?.togglePlayback || (() => {}),
|
|
108
|
+
}),
|
|
109
|
+
// Include 'isPlaying' as dependency because 'togglePlayback' changes when it changes
|
|
110
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
111
|
+
[toggleFullscreen, isPlaying]
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<MediaPlaybackWrapper
|
|
116
|
+
media={videoMediaObject as Playback | undefined}
|
|
117
|
+
isPlaying={isPlaying}
|
|
118
|
+
ref={mediaPlaybackWrapperRef}
|
|
119
|
+
>
|
|
120
|
+
<VideoPlayerComponent
|
|
121
|
+
// https://docs.expo.dev/versions/latest/sdk/av/#example-video to see why ref is handled this way
|
|
122
|
+
ref={(component) => setVideoMediaObject(component)}
|
|
123
|
+
style={style}
|
|
124
|
+
videoStyle={sizeStyles}
|
|
125
|
+
resizeMode={mappedResizeMode}
|
|
126
|
+
posterStyle={[sizeStyles, { resizeMode: posterResizeMode }]}
|
|
127
|
+
onPlaybackStatusUpdate={onPlaybackStatusUpdate}
|
|
128
|
+
onFullscreenUpdate={(e) => onFullscreenUpdate(e.fullscreenUpdate)}
|
|
129
|
+
{...rest}
|
|
130
|
+
/>
|
|
131
|
+
</MediaPlaybackWrapper>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
export default VideoPlayer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import React, { useEffect, useState } from "react";
|
|
2
|
-
import { TextInput } from "react-native";
|
|
2
|
+
import { TextInput as NativeTextInput } from "react-native";
|
|
3
3
|
import { isString, isNumber, isNaN } from "lodash";
|
|
4
|
-
|
|
4
|
+
import { useDebounce } from "../hooks";
|
|
5
|
+
const NumberInput = React.forwardRef(({ onChangeText, onChangeTextDelayed, changeTextDelay = 500, value, defaultValue, ...props }, ref) => {
|
|
5
6
|
const [currentStringNumberValue, setCurrentStringNumberValue] = useState("");
|
|
7
|
+
const delayedValue = useDebounce(value, changeTextDelay);
|
|
6
8
|
const formatValueToStringNumber = (valueToFormat) => {
|
|
7
9
|
if (valueToFormat != null) {
|
|
8
10
|
if (isString(valueToFormat) && valueToFormat !== "") {
|
|
@@ -44,7 +46,15 @@ const NumberInput = React.forwardRef(({ onChangeText, value, defaultValue, ...pr
|
|
|
44
46
|
}
|
|
45
47
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
46
48
|
}, []);
|
|
47
|
-
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (delayedValue !== undefined) {
|
|
51
|
+
const newStringNumberValue = formatValueToStringNumber(delayedValue);
|
|
52
|
+
const number = parseFloat(newStringNumberValue);
|
|
53
|
+
onChangeTextDelayed === null || onChangeTextDelayed === void 0 ? void 0 : onChangeTextDelayed(number);
|
|
54
|
+
}
|
|
55
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
56
|
+
}, [delayedValue]);
|
|
57
|
+
return (React.createElement(NativeTextInput, { testID: "native-text-input", ref: ref, keyboardType: "numeric", value: currentStringNumberValue, onChangeText: handleChangeText, ...props }));
|
|
48
58
|
});
|
|
49
59
|
export default NumberInput;
|
|
50
60
|
//# sourceMappingURL=NumberInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberInput.js","sourceRoot":"","sources":["NumberInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"NumberInput.js","sourceRoot":"","sources":["NumberInput.ts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AK,GACT,CACH,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -1,18 +1,37 @@
|
|
|
1
1
|
import React, { useEffect, useState } from "react";
|
|
2
|
-
import { TextInput } from "react-native";
|
|
2
|
+
import { TextInput as NativeTextInput } from "react-native";
|
|
3
3
|
import { isString, isNumber, isNaN } from "lodash";
|
|
4
|
+
import { TextInputProps } from "./TextInput";
|
|
5
|
+
import { useDebounce } from "../hooks";
|
|
4
6
|
|
|
5
|
-
interface Props
|
|
7
|
+
interface Props
|
|
8
|
+
extends Omit<
|
|
9
|
+
TextInputProps,
|
|
10
|
+
"value" | "onChangeText" | "defaultValue" | "onChangeTextDelayed"
|
|
11
|
+
> {
|
|
6
12
|
value?: number | string;
|
|
7
13
|
defaultValue?: number | string;
|
|
8
14
|
onChangeText?: (value?: number) => void;
|
|
15
|
+
onChangeTextDelayed?: (value?: number) => void;
|
|
9
16
|
}
|
|
10
17
|
|
|
11
|
-
const NumberInput = React.forwardRef<
|
|
12
|
-
(
|
|
18
|
+
const NumberInput = React.forwardRef<NativeTextInput, Props>(
|
|
19
|
+
(
|
|
20
|
+
{
|
|
21
|
+
onChangeText,
|
|
22
|
+
onChangeTextDelayed,
|
|
23
|
+
changeTextDelay = 500,
|
|
24
|
+
value,
|
|
25
|
+
defaultValue,
|
|
26
|
+
...props
|
|
27
|
+
},
|
|
28
|
+
ref
|
|
29
|
+
) => {
|
|
13
30
|
const [currentStringNumberValue, setCurrentStringNumberValue] =
|
|
14
31
|
useState("");
|
|
15
32
|
|
|
33
|
+
const delayedValue = useDebounce(value, changeTextDelay);
|
|
34
|
+
|
|
16
35
|
const formatValueToStringNumber = (valueToFormat?: number | string) => {
|
|
17
36
|
if (valueToFormat != null) {
|
|
18
37
|
if (isString(valueToFormat) && valueToFormat !== "") {
|
|
@@ -59,8 +78,18 @@ const NumberInput = React.forwardRef<TextInput, Props>(
|
|
|
59
78
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
60
79
|
}, []);
|
|
61
80
|
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
if (delayedValue !== undefined) {
|
|
83
|
+
const newStringNumberValue = formatValueToStringNumber(delayedValue);
|
|
84
|
+
const number = parseFloat(newStringNumberValue);
|
|
85
|
+
onChangeTextDelayed?.(number);
|
|
86
|
+
}
|
|
87
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
88
|
+
}, [delayedValue]);
|
|
89
|
+
|
|
62
90
|
return (
|
|
63
|
-
<
|
|
91
|
+
<NativeTextInput
|
|
92
|
+
testID="native-text-input"
|
|
64
93
|
ref={ref}
|
|
65
94
|
keyboardType="numeric"
|
|
66
95
|
value={currentStringNumberValue}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import Svg, { Path } from "react-native-svg";
|
|
3
|
+
import Animated, { useAnimatedProps, useSharedValue, withTiming, } from "react-native-reanimated";
|
|
4
|
+
import { DEFAULT_ANIMATION_DURATION, } from "../ProgressCommon";
|
|
5
|
+
export const AnimatedPath = Animated.createAnimatedComponent(Path);
|
|
6
|
+
export const CircularProgress = ({ theme, minimumValue = 0, maximumValue = 100, value = minimumValue, thickness = 10, trackThickness = thickness, color = theme.colors.primary, trackColor = theme.colors.divider, trackOpacity = 1, showTrack = true, animationDuration = DEFAULT_ANIMATION_DURATION, isAnimated = true, lineCap = "round", trackLineCap = lineCap, dashWidth, trackDashWidth, dashGap, trackDashGap, dashOffset, trackDashOffset, customDashArray, trackCustomDashArray, onFullPathWidth, startPosition = "top", style, testID, }) => {
|
|
7
|
+
const [svgContainerWidth, setSvgContainerWidth] = React.useState(0);
|
|
8
|
+
const [circumfrence, setCircumefrence] = React.useState(0);
|
|
9
|
+
const dashArray = dashWidth !== undefined
|
|
10
|
+
? `${dashWidth} ${dashGap || dashWidth}`
|
|
11
|
+
: undefined;
|
|
12
|
+
const trackDashArray = trackDashWidth !== undefined
|
|
13
|
+
? `${trackDashWidth} ${trackDashGap || trackDashWidth}`
|
|
14
|
+
: undefined;
|
|
15
|
+
const maxThickness = Math.max(thickness, trackThickness);
|
|
16
|
+
const thicknessOffset = maxThickness / 2; // This offset guarantees nothing is cut off by view bounds
|
|
17
|
+
const radius = svgContainerWidth / 2;
|
|
18
|
+
const c = 2 * Math.PI * radius;
|
|
19
|
+
if (c !== circumfrence) {
|
|
20
|
+
setCircumefrence(c);
|
|
21
|
+
}
|
|
22
|
+
const startAngle = React.useMemo(() => {
|
|
23
|
+
switch (startPosition) {
|
|
24
|
+
case "top":
|
|
25
|
+
return 0;
|
|
26
|
+
case "right":
|
|
27
|
+
return 90;
|
|
28
|
+
case "bottom":
|
|
29
|
+
return 180;
|
|
30
|
+
case "left":
|
|
31
|
+
return 270;
|
|
32
|
+
}
|
|
33
|
+
}, [startPosition]);
|
|
34
|
+
const currentFillPercentage = value / (maximumValue + minimumValue);
|
|
35
|
+
const currentAngle = useSharedValue(startAngle + currentFillPercentage * 360);
|
|
36
|
+
const progressPathAnimatedProps = useAnimatedProps(() => {
|
|
37
|
+
const isBelowMinAngle = currentAngle.value <= startAngle;
|
|
38
|
+
return {
|
|
39
|
+
d: circlePath(radius, radius, radius - thicknessOffset, startAngle, Math.min(currentAngle.value, startAngle + 360) //Prevents going beyond the max angle
|
|
40
|
+
),
|
|
41
|
+
strokeOpacity: isBelowMinAngle ? 0.0 : 1.0,
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
React.useEffect(() => {
|
|
45
|
+
currentAngle.value = withTiming(startAngle + currentFillPercentage * 360, {
|
|
46
|
+
duration: isAnimated ? animationDuration : 0,
|
|
47
|
+
});
|
|
48
|
+
}, [
|
|
49
|
+
value,
|
|
50
|
+
currentFillPercentage,
|
|
51
|
+
animationDuration,
|
|
52
|
+
currentAngle,
|
|
53
|
+
maximumValue,
|
|
54
|
+
minimumValue,
|
|
55
|
+
isAnimated,
|
|
56
|
+
startAngle,
|
|
57
|
+
]);
|
|
58
|
+
React.useEffect(() => {
|
|
59
|
+
onFullPathWidth === null || onFullPathWidth === void 0 ? void 0 : onFullPathWidth(circumfrence);
|
|
60
|
+
}, [circumfrence, onFullPathWidth]);
|
|
61
|
+
return (React.createElement(Svg, { testID: testID !== null && testID !== void 0 ? testID : "circular-progress-component", onLayout: (event) => {
|
|
62
|
+
const width = event.nativeEvent.layout.width;
|
|
63
|
+
setSvgContainerWidth(width);
|
|
64
|
+
}, style: [
|
|
65
|
+
{
|
|
66
|
+
height: svgContainerWidth,
|
|
67
|
+
},
|
|
68
|
+
style,
|
|
69
|
+
] },
|
|
70
|
+
showTrack && (React.createElement(Path, { d: circlePath(radius, radius, radius - thicknessOffset, startAngle, startAngle + 360), stroke: trackColor, strokeWidth: trackThickness, strokeOpacity: trackOpacity, strokeLinecap: trackLineCap, strokeDasharray: trackCustomDashArray || trackDashArray, strokeDashoffset: trackDashOffset })),
|
|
71
|
+
React.createElement(AnimatedPath, { animatedProps: progressPathAnimatedProps, stroke: color, strokeWidth: thickness, strokeLinecap: lineCap, strokeDasharray: customDashArray || dashArray, strokeDashoffset: dashOffset })));
|
|
72
|
+
};
|
|
73
|
+
// From: https://github.com/bartgryszko/react-native-circular-progress/blob/a93b501aea40306126c8ede72089741eead52308/src/CircularProgress.js#L15
|
|
74
|
+
function circlePath(x, y, radius, startAngle, endAngle) {
|
|
75
|
+
"worklet"; // Reanimated worklet to be runnable on the UI thread
|
|
76
|
+
function polarToCartesian(centerX, centerY, radius, angleInDegrees) {
|
|
77
|
+
var angleInRadians = ((angleInDegrees - 90) * Math.PI) / 180.0;
|
|
78
|
+
return {
|
|
79
|
+
x: centerX + radius * Math.cos(angleInRadians),
|
|
80
|
+
y: centerY + radius * Math.sin(angleInRadians),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
var start = polarToCartesian(x, y, radius, endAngle * 0.9999);
|
|
84
|
+
var end = polarToCartesian(x, y, radius, startAngle);
|
|
85
|
+
var largeArcFlag = endAngle - startAngle <= 180 ? "0" : "1";
|
|
86
|
+
var d = [
|
|
87
|
+
"M",
|
|
88
|
+
start.x,
|
|
89
|
+
start.y,
|
|
90
|
+
"A",
|
|
91
|
+
radius,
|
|
92
|
+
radius,
|
|
93
|
+
0,
|
|
94
|
+
largeArcFlag,
|
|
95
|
+
0,
|
|
96
|
+
end.x,
|
|
97
|
+
end.y,
|
|
98
|
+
];
|
|
99
|
+
return d.join(" ");
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=CircularProgress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CircularProgress.js","sourceRoot":"","sources":["CircularProgress.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAG,EAAE,EAAE,IAAI,EAAa,MAAM,kBAAkB,CAAC;AACxD,OAAO,QAAQ,EAAE,EACf,gBAAgB,EAChB,cAAc,EACd,UAAU,GACX,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,0BAA0B,GAG3B,MAAM,mBAAmB,CAAC;AAE3B,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC,uBAAuB,CAAC,IAAI,CAAC,CAAC;AAEnE,MAAM,CAAC,MAAM,gBAAgB,GAEzB,CAAC,EACH,KAAK,EACL,YAAY,GAAG,CAAC,EAChB,YAAY,GAAG,GAAG,EAClB,KAAK,GAAG,YAAY,EACpB,SAAS,GAAG,EAAE,EACd,cAAc,GAAG,SAAS,EAC1B,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,EAC5B,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,EACjC,YAAY,GAAG,CAAC,EAChB,SAAS,GAAG,IAAI,EAChB,iBAAiB,GAAG,0BAA0B,EAC9C,UAAU,GAAG,IAAI,EACjB,OAAO,GAAG,OAAO,EACjB,YAAY,GAAG,OAAO,EACtB,SAAS,EACT,cAAc,EACd,OAAO,EACP,YAAY,EACZ,UAAU,EACV,eAAe,EACf,eAAe,E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C,EAAE,MAAM,EAAE,QAAQ,GAAG,MAAM,CAAC,CAAC;IAC9D,IAAI,GAAG,GAAG,gBAAgB,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IACrD,IAAI,YAAY,GAAG,QAAQ,GAAG,UAAU,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IAC5D,IAAI,CAAC,GAAG;QACN,GAAG;QACH,KAAK,CAAC,CAAC;QACP,KAAK,CAAC,CAAC;QACP,GAAG;QACH,MAAM;QACN,MAAM;QACN,CAAC;QACD,YAAY;QACZ,CAAC;QACD,GAAG,CAAC,CAAC;QACL,GAAG,CAAC,CAAC;KACN,CAAC;IACF,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import Svg, { Path, PathProps } from "react-native-svg";
|
|
3
|
+
import Animated, {
|
|
4
|
+
useAnimatedProps,
|
|
5
|
+
useSharedValue,
|
|
6
|
+
withTiming,
|
|
7
|
+
} from "react-native-reanimated";
|
|
8
|
+
import {
|
|
9
|
+
DEFAULT_ANIMATION_DURATION,
|
|
10
|
+
ValueProgressProps,
|
|
11
|
+
CircularProgressProps,
|
|
12
|
+
} from "../ProgressCommon";
|
|
13
|
+
|
|
14
|
+
export const AnimatedPath = Animated.createAnimatedComponent(Path);
|
|
15
|
+
|
|
16
|
+
export const CircularProgress: React.FC<
|
|
17
|
+
ValueProgressProps & CircularProgressProps
|
|
18
|
+
> = ({
|
|
19
|
+
theme,
|
|
20
|
+
minimumValue = 0,
|
|
21
|
+
maximumValue = 100,
|
|
22
|
+
value = minimumValue,
|
|
23
|
+
thickness = 10,
|
|
24
|
+
trackThickness = thickness,
|
|
25
|
+
color = theme.colors.primary,
|
|
26
|
+
trackColor = theme.colors.divider,
|
|
27
|
+
trackOpacity = 1,
|
|
28
|
+
showTrack = true,
|
|
29
|
+
animationDuration = DEFAULT_ANIMATION_DURATION,
|
|
30
|
+
isAnimated = true,
|
|
31
|
+
lineCap = "round",
|
|
32
|
+
trackLineCap = lineCap,
|
|
33
|
+
dashWidth,
|
|
34
|
+
trackDashWidth,
|
|
35
|
+
dashGap,
|
|
36
|
+
trackDashGap,
|
|
37
|
+
dashOffset,
|
|
38
|
+
trackDashOffset,
|
|
39
|
+
customDashArray,
|
|
40
|
+
trackCustomDashArray,
|
|
41
|
+
onFullPathWidth,
|
|
42
|
+
startPosition = "top",
|
|
43
|
+
style,
|
|
44
|
+
testID,
|
|
45
|
+
}) => {
|
|
46
|
+
const [svgContainerWidth, setSvgContainerWidth] = React.useState(0);
|
|
47
|
+
const [circumfrence, setCircumefrence] = React.useState(0);
|
|
48
|
+
|
|
49
|
+
const dashArray =
|
|
50
|
+
dashWidth !== undefined
|
|
51
|
+
? `${dashWidth} ${dashGap || dashWidth}`
|
|
52
|
+
: undefined;
|
|
53
|
+
const trackDashArray =
|
|
54
|
+
trackDashWidth !== undefined
|
|
55
|
+
? `${trackDashWidth} ${trackDashGap || trackDashWidth}`
|
|
56
|
+
: undefined;
|
|
57
|
+
|
|
58
|
+
const maxThickness = Math.max(thickness, trackThickness);
|
|
59
|
+
const thicknessOffset = maxThickness / 2; // This offset guarantees nothing is cut off by view bounds
|
|
60
|
+
|
|
61
|
+
const radius = svgContainerWidth / 2;
|
|
62
|
+
|
|
63
|
+
const c = 2 * Math.PI * radius;
|
|
64
|
+
if (c !== circumfrence) {
|
|
65
|
+
setCircumefrence(c);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const startAngle = React.useMemo(() => {
|
|
69
|
+
switch (startPosition) {
|
|
70
|
+
case "top":
|
|
71
|
+
return 0;
|
|
72
|
+
case "right":
|
|
73
|
+
return 90;
|
|
74
|
+
case "bottom":
|
|
75
|
+
return 180;
|
|
76
|
+
case "left":
|
|
77
|
+
return 270;
|
|
78
|
+
}
|
|
79
|
+
}, [startPosition]);
|
|
80
|
+
|
|
81
|
+
const currentFillPercentage = value / (maximumValue + minimumValue);
|
|
82
|
+
const currentAngle = useSharedValue(startAngle + currentFillPercentage * 360);
|
|
83
|
+
|
|
84
|
+
const progressPathAnimatedProps = useAnimatedProps<PathProps>(() => {
|
|
85
|
+
const isBelowMinAngle = currentAngle.value <= startAngle;
|
|
86
|
+
return {
|
|
87
|
+
d: circlePath(
|
|
88
|
+
radius,
|
|
89
|
+
radius,
|
|
90
|
+
radius - thicknessOffset,
|
|
91
|
+
startAngle,
|
|
92
|
+
Math.min(currentAngle.value, startAngle + 360) //Prevents going beyond the max angle
|
|
93
|
+
),
|
|
94
|
+
strokeOpacity: isBelowMinAngle ? 0.0 : 1.0,
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
React.useEffect(() => {
|
|
99
|
+
currentAngle.value = withTiming(startAngle + currentFillPercentage * 360, {
|
|
100
|
+
duration: isAnimated ? animationDuration : 0,
|
|
101
|
+
});
|
|
102
|
+
}, [
|
|
103
|
+
value,
|
|
104
|
+
currentFillPercentage,
|
|
105
|
+
animationDuration,
|
|
106
|
+
currentAngle,
|
|
107
|
+
maximumValue,
|
|
108
|
+
minimumValue,
|
|
109
|
+
isAnimated,
|
|
110
|
+
startAngle,
|
|
111
|
+
]);
|
|
112
|
+
|
|
113
|
+
React.useEffect(() => {
|
|
114
|
+
onFullPathWidth?.(circumfrence);
|
|
115
|
+
}, [circumfrence, onFullPathWidth]);
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<Svg
|
|
119
|
+
testID={testID ?? "circular-progress-component"}
|
|
120
|
+
onLayout={(event) => {
|
|
121
|
+
const width = event.nativeEvent.layout.width;
|
|
122
|
+
setSvgContainerWidth(width);
|
|
123
|
+
}}
|
|
124
|
+
style={[
|
|
125
|
+
{
|
|
126
|
+
height: svgContainerWidth,
|
|
127
|
+
},
|
|
128
|
+
style,
|
|
129
|
+
]}
|
|
130
|
+
>
|
|
131
|
+
{showTrack && (
|
|
132
|
+
<Path
|
|
133
|
+
d={circlePath(
|
|
134
|
+
radius,
|
|
135
|
+
radius,
|
|
136
|
+
radius - thicknessOffset,
|
|
137
|
+
startAngle,
|
|
138
|
+
startAngle + 360
|
|
139
|
+
)}
|
|
140
|
+
stroke={trackColor}
|
|
141
|
+
strokeWidth={trackThickness}
|
|
142
|
+
strokeOpacity={trackOpacity}
|
|
143
|
+
strokeLinecap={trackLineCap}
|
|
144
|
+
strokeDasharray={trackCustomDashArray || trackDashArray}
|
|
145
|
+
strokeDashoffset={trackDashOffset}
|
|
146
|
+
/>
|
|
147
|
+
)}
|
|
148
|
+
<AnimatedPath
|
|
149
|
+
animatedProps={progressPathAnimatedProps}
|
|
150
|
+
stroke={color}
|
|
151
|
+
strokeWidth={thickness}
|
|
152
|
+
strokeLinecap={lineCap}
|
|
153
|
+
strokeDasharray={customDashArray || dashArray}
|
|
154
|
+
strokeDashoffset={dashOffset}
|
|
155
|
+
/>
|
|
156
|
+
</Svg>
|
|
157
|
+
);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// From: https://github.com/bartgryszko/react-native-circular-progress/blob/a93b501aea40306126c8ede72089741eead52308/src/CircularProgress.js#L15
|
|
161
|
+
function circlePath(
|
|
162
|
+
x: number,
|
|
163
|
+
y: number,
|
|
164
|
+
radius: number,
|
|
165
|
+
startAngle: number,
|
|
166
|
+
endAngle: number
|
|
167
|
+
) {
|
|
168
|
+
"worklet"; // Reanimated worklet to be runnable on the UI thread
|
|
169
|
+
|
|
170
|
+
function polarToCartesian(
|
|
171
|
+
centerX: number,
|
|
172
|
+
centerY: number,
|
|
173
|
+
radius: number,
|
|
174
|
+
angleInDegrees: number
|
|
175
|
+
) {
|
|
176
|
+
var angleInRadians = ((angleInDegrees - 90) * Math.PI) / 180.0;
|
|
177
|
+
return {
|
|
178
|
+
x: centerX + radius * Math.cos(angleInRadians),
|
|
179
|
+
y: centerY + radius * Math.sin(angleInRadians),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
var start = polarToCartesian(x, y, radius, endAngle * 0.9999);
|
|
184
|
+
var end = polarToCartesian(x, y, radius, startAngle);
|
|
185
|
+
var largeArcFlag = endAngle - startAngle <= 180 ? "0" : "1";
|
|
186
|
+
var d = [
|
|
187
|
+
"M",
|
|
188
|
+
start.x,
|
|
189
|
+
start.y,
|
|
190
|
+
"A",
|
|
191
|
+
radius,
|
|
192
|
+
radius,
|
|
193
|
+
0,
|
|
194
|
+
largeArcFlag,
|
|
195
|
+
0,
|
|
196
|
+
end.x,
|
|
197
|
+
end.y,
|
|
198
|
+
];
|
|
199
|
+
return d.join(" ");
|
|
200
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import IndeterminateProgress from "../IndeterminateProgress";
|
|
3
|
+
import { CircularProgress as CircularProgressComponent } from "./CircularProgress";
|
|
4
|
+
import { withTheme } from "../../../theming";
|
|
5
|
+
const CircularProgress = (props) => {
|
|
6
|
+
if (props.indeterminate) {
|
|
7
|
+
return (React.createElement(IndeterminateProgress, { ProgressComponent: CircularProgressComponent, ...props }));
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
return React.createElement(CircularProgressComponent, { ...props });
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export default withTheme(CircularProgress);
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,qBAAqB,MAAM,0BAA0B,CAAC;AAM7D,OAAO,EAAE,gBAAgB,IAAI,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,MAAM,gBAAgB,GAElB,CAAC,KAAK,EAAE,EAAE;IACZ,IAAI,KAAK,CAAC,aAAa,EAAE;QACvB,OAAO,CACL,oBAAC,qBAAqB,IACpB,iBAAiB,EACf,yBAAwE,KAEtE,KAAK,GACT,CACH,CAAC;KACH;SAAM;QACL,OAAO,oBAAC,yBAAyB,OAAK,KAAK,GAAI,CAAC;KACjD;AACH,CAAC,CAAC;AAEF,eAAe,SAAS,CAAC,gBAAgB,CAAC,CAAC"}
|