@shopify/react-native-skia
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -8,4 +8,6 @@ import { type SharedValue } from "react-native-reanimated"; | ||
paused: Animated<boolean>; | ||
seek: Animated<number | null>; | ||
currentTime: Animated<number>; | ||
} | ||
export declare const useVideo: (source: string | null, userOptions?: Partial<PlaybackOptions>) => SharedValue<SkImage | null>; | ||
export {}; |
@@ -16,3 +16,5 @@ "use strict"; | ||
looping: true, | ||
paused: false | ||
paused: false, | ||
seek: null, | ||
currentTime: 0 | ||
}; | ||
@@ -27,6 +29,8 @@ const useOption = value => { | ||
const useVideo = (source, userOptions) => { | ||
var _userOptions$paused, _userOptions$looping, _userOptions$playback; | ||
var _userOptions$paused, _userOptions$looping, _userOptions$seek, _userOptions$currentT, _userOptions$playback; | ||
const video = (0, _react.useMemo)(() => source ? _Skia.Skia.Video(source) : null, [source]); | ||
const isPaused = useOption((_userOptions$paused = userOptions === null || userOptions === void 0 ? void 0 : userOptions.paused) !== null && _userOptions$paused !== void 0 ? _userOptions$paused : defaultOptions.paused); | ||
const looping = useOption((_userOptions$looping = userOptions === null || userOptions === void 0 ? void 0 : userOptions.looping) !== null && _userOptions$looping !== void 0 ? _userOptions$looping : defaultOptions.looping); | ||
const seek = useOption((_userOptions$seek = userOptions === null || userOptions === void 0 ? void 0 : userOptions.seek) !== null && _userOptions$seek !== void 0 ? _userOptions$seek : defaultOptions.seek); | ||
const currentTime = useOption((_userOptions$currentT = userOptions === null || userOptions === void 0 ? void 0 : userOptions.currentTime) !== null && _userOptions$currentT !== void 0 ? _userOptions$currentT : defaultOptions.currentTime); | ||
const playbackSpeed = useOption((_userOptions$playback = userOptions === null || userOptions === void 0 ? void 0 : userOptions.playbackSpeed) !== null && _userOptions$playback !== void 0 ? _userOptions$playback : defaultOptions.playbackSpeed); | ||
@@ -48,2 +52,8 @@ const currentFrame = _ReanimatedProxy.default.useSharedValue(null); | ||
} | ||
if (seek.value !== null) { | ||
video.seek(seek.value); | ||
seek.value = null; | ||
lastTimestamp.value = -1; | ||
startTimestamp.value = -1; | ||
} | ||
if (isPaused.value && lastTimestamp.value !== -1) { | ||
@@ -63,2 +73,3 @@ return; | ||
const currentTimestamp = timestamp - startTimestamp.value; | ||
currentTime.value = currentTimestamp; | ||
@@ -72,4 +83,5 @@ // Handle looping | ||
// Update frame only if the elapsed time since last update is greater than the frame duration | ||
const currentFrameDuration = frameDuration / playbackSpeed.value; | ||
if (lastTimestamp.value === -1 || timestamp - lastTimestamp.value >= currentFrameDuration) { | ||
const currentFrameDuration = Math.floor(frameDuration / playbackSpeed.value); | ||
const delta = Math.floor(timestamp - lastTimestamp.value); | ||
if (lastTimestamp.value === -1 || delta >= currentFrameDuration) { | ||
const img = video.nextImage(); | ||
@@ -76,0 +88,0 @@ if (img) { |
@@ -8,4 +8,6 @@ import { type SharedValue } from "react-native-reanimated"; | ||
paused: Animated<boolean>; | ||
seek: Animated<number | null>; | ||
currentTime: Animated<number>; | ||
} | ||
export declare const useVideo: (source: string | null, userOptions?: Partial<PlaybackOptions>) => SharedValue<SkImage | null>; | ||
export {}; |
@@ -9,3 +9,5 @@ import { runOnUI, useSharedValue } from "react-native-reanimated"; | ||
looping: true, | ||
paused: false | ||
paused: false, | ||
seek: null, | ||
currentTime: 0 | ||
}; | ||
@@ -20,6 +22,8 @@ const useOption = value => { | ||
export const useVideo = (source, userOptions) => { | ||
var _userOptions$paused, _userOptions$looping, _userOptions$playback; | ||
var _userOptions$paused, _userOptions$looping, _userOptions$seek, _userOptions$currentT, _userOptions$playback; | ||
const video = useMemo(() => source ? Skia.Video(source) : null, [source]); | ||
const isPaused = useOption((_userOptions$paused = userOptions === null || userOptions === void 0 ? void 0 : userOptions.paused) !== null && _userOptions$paused !== void 0 ? _userOptions$paused : defaultOptions.paused); | ||
const looping = useOption((_userOptions$looping = userOptions === null || userOptions === void 0 ? void 0 : userOptions.looping) !== null && _userOptions$looping !== void 0 ? _userOptions$looping : defaultOptions.looping); | ||
const seek = useOption((_userOptions$seek = userOptions === null || userOptions === void 0 ? void 0 : userOptions.seek) !== null && _userOptions$seek !== void 0 ? _userOptions$seek : defaultOptions.seek); | ||
const currentTime = useOption((_userOptions$currentT = userOptions === null || userOptions === void 0 ? void 0 : userOptions.currentTime) !== null && _userOptions$currentT !== void 0 ? _userOptions$currentT : defaultOptions.currentTime); | ||
const playbackSpeed = useOption((_userOptions$playback = userOptions === null || userOptions === void 0 ? void 0 : userOptions.playbackSpeed) !== null && _userOptions$playback !== void 0 ? _userOptions$playback : defaultOptions.playbackSpeed); | ||
@@ -41,2 +45,8 @@ const currentFrame = Rea.useSharedValue(null); | ||
} | ||
if (seek.value !== null) { | ||
video.seek(seek.value); | ||
seek.value = null; | ||
lastTimestamp.value = -1; | ||
startTimestamp.value = -1; | ||
} | ||
if (isPaused.value && lastTimestamp.value !== -1) { | ||
@@ -56,2 +66,3 @@ return; | ||
const currentTimestamp = timestamp - startTimestamp.value; | ||
currentTime.value = currentTimestamp; | ||
@@ -65,4 +76,5 @@ // Handle looping | ||
// Update frame only if the elapsed time since last update is greater than the frame duration | ||
const currentFrameDuration = frameDuration / playbackSpeed.value; | ||
if (lastTimestamp.value === -1 || timestamp - lastTimestamp.value >= currentFrameDuration) { | ||
const currentFrameDuration = Math.floor(frameDuration / playbackSpeed.value); | ||
const delta = Math.floor(timestamp - lastTimestamp.value); | ||
if (lastTimestamp.value === -1 || delta >= currentFrameDuration) { | ||
const img = video.nextImage(); | ||
@@ -69,0 +81,0 @@ if (img) { |
@@ -8,4 +8,6 @@ import { type SharedValue } from "react-native-reanimated"; | ||
paused: Animated<boolean>; | ||
seek: Animated<number | null>; | ||
currentTime: Animated<number>; | ||
} | ||
export declare const useVideo: (source: string | null, userOptions?: Partial<PlaybackOptions>) => SharedValue<SkImage | null>; | ||
export {}; |
@@ -10,3 +10,3 @@ { | ||
"title": "React Native Skia", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "High-performance React Native Graphics using Skia", | ||
@@ -13,0 +13,0 @@ "main": "lib/module/index.js", |
@@ -21,2 +21,4 @@ import { | ||
paused: Animated<boolean>; | ||
seek: Animated<number | null>; | ||
currentTime: Animated<number>; | ||
} | ||
@@ -28,2 +30,4 @@ | ||
paused: false, | ||
seek: null, | ||
currentTime: 0, | ||
}; | ||
@@ -47,2 +51,6 @@ | ||
const looping = useOption(userOptions?.looping ?? defaultOptions.looping); | ||
const seek = useOption(userOptions?.seek ?? defaultOptions.seek); | ||
const currentTime = useOption( | ||
userOptions?.currentTime ?? defaultOptions.currentTime | ||
); | ||
const playbackSpeed = useOption( | ||
@@ -70,2 +78,8 @@ userOptions?.playbackSpeed ?? defaultOptions.playbackSpeed | ||
} | ||
if (seek.value !== null) { | ||
video.seek(seek.value); | ||
seek.value = null; | ||
lastTimestamp.value = -1; | ||
startTimestamp.value = -1; | ||
} | ||
if (isPaused.value && lastTimestamp.value !== -1) { | ||
@@ -83,2 +97,3 @@ return; | ||
const currentTimestamp = timestamp - startTimestamp.value; | ||
currentTime.value = currentTimestamp; | ||
@@ -92,7 +107,7 @@ // Handle looping | ||
// Update frame only if the elapsed time since last update is greater than the frame duration | ||
const currentFrameDuration = frameDuration / playbackSpeed.value; | ||
if ( | ||
lastTimestamp.value === -1 || | ||
timestamp - lastTimestamp.value >= currentFrameDuration | ||
) { | ||
const currentFrameDuration = Math.floor( | ||
frameDuration / playbackSpeed.value | ||
); | ||
const delta = Math.floor(timestamp - lastTimestamp.value); | ||
if (lastTimestamp.value === -1 || delta >= currentFrameDuration) { | ||
const img = video.nextImage(); | ||
@@ -99,0 +114,0 @@ if (img) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
224163857
55731