@draftbit/core 50.2.9-c89444.2 → 50.3.1-1aeb3f.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/commonjs/components/Timer.js +1 -1
- package/lib/typescript/src/components/Timer.d.ts +2 -2
- package/lib/typescript/src/components/Timer.js +13 -7
- package/lib/typescript/src/components/Timer.js.map +1 -1
- package/lib/typescript/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/components/Timer.js +13 -7
- package/src/components/Timer.js.map +1 -1
- package/src/components/Timer.tsx +23 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
import _slicedToArray from"@babel/runtime/helpers/slicedToArray";var _this=this,_jsxFileName="/home/runner/work/react-native-jigsaw/react-native-jigsaw/packages/core/src/components/Timer.tsx";import React,{useState,useEffect,useRef,useImperativeHandle,forwardRef}from"react";import{Text,StyleSheet}from"react-native";import{jsx as _jsx}from"react/jsx-runtime";var Timer=forwardRef(function(_ref,ref){var style=_ref.style,initialTime=_ref.initialTime,_ref$updateInterval=_ref.updateInterval,updateInterval=_ref$updateInterval===void 0?1000:_ref$updateInterval,_ref$format=_ref.format,format=_ref$format===void 0?"mm:ss":_ref$format,onTimerChange=_ref.onTimerChange,onTimerEnd=_ref.onTimerEnd,_ref$countDirection=_ref.countDirection,countDirection=_ref$countDirection===void 0?"up":_ref$countDirection,timerEndTime=_ref.timerEndTime;var defaultInitialTime=
|
|
1
|
+
import _slicedToArray from"@babel/runtime/helpers/slicedToArray";import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";var _excluded=["style","initialTime","updateInterval","format","onTimerChange","onTimerEnd","countDirection","timerEndTime"];var _this=this,_jsxFileName="/home/runner/work/react-native-jigsaw/react-native-jigsaw/packages/core/src/components/Timer.tsx";import React,{useState,useEffect,useRef,useImperativeHandle,forwardRef}from"react";import{Text,StyleSheet}from"react-native";import{jsx as _jsx}from"react/jsx-runtime";var Timer=forwardRef(function(_ref,ref){var style=_ref.style,initialTime=_ref.initialTime,_ref$updateInterval=_ref.updateInterval,updateInterval=_ref$updateInterval===void 0?1000:_ref$updateInterval,_ref$format=_ref.format,format=_ref$format===void 0?"mm:ss":_ref$format,onTimerChange=_ref.onTimerChange,onTimerEnd=_ref.onTimerEnd,_ref$countDirection=_ref.countDirection,countDirection=_ref$countDirection===void 0?"up":_ref$countDirection,timerEndTime=_ref.timerEndTime,rest=_objectWithoutProperties(_ref,_excluded);var defaultInitialTime=0;var _useState=useState(initialTime!=null?initialTime:defaultInitialTime),_useState2=_slicedToArray(_useState,2),time=_useState2[0],setTime=_useState2[1];var timerRef=useRef(null);useEffect(function(){onTimerChange==null?void 0:onTimerChange(time);},[time]);useImperativeHandle(ref,function(){return{start:startTimer,stop:stopTimer,reset:resetTimer};});var startTimer=function startTimer(){if(timerRef.current)return;timerRef.current=setInterval(function(){setTime(function(prevTime){var newTime=countDirection==="up"?prevTime+updateInterval:prevTime-updateInterval;if(newTime<=0&&countDirection==="down"){clearTimer();setTimeout(function(){onTimerEnd==null?void 0:onTimerEnd();},updateInterval);return 0;}if(countDirection==="up"&&timerEndTime!==undefined&&newTime>=timerEndTime){clearTimer();setTimeout(function(){onTimerEnd==null?void 0:onTimerEnd();},updateInterval);return timerEndTime;}return newTime;});},updateInterval);};var stopTimer=function stopTimer(){return clearTimer();};var resetTimer=function resetTimer(){var newTime=arguments.length>0&&arguments[0]!==undefined?arguments[0]:initialTime!=null?initialTime:defaultInitialTime;clearTimer();setTime(newTime);};var clearTimer=function clearTimer(){if(timerRef.current){clearInterval(timerRef.current);timerRef.current=null;}};useEffect(function(){return function(){return clearTimer();};},[]);var formatTime=function formatTime(milliseconds){var totalSeconds=Math.floor(milliseconds/1000);var hours=Math.floor(totalSeconds/3600);var minutes=Math.floor((totalSeconds-hours*3600)/60);var seconds=totalSeconds-hours*3600-minutes*60;var ms=milliseconds%1000;var formattedHours=String(hours).padStart(2,"0");var formattedMinutes=String(minutes).padStart(2,"0");var formattedSeconds=String(seconds).padStart(2,"0");var formattedMs=String(ms).padStart(3,"0");return format.replace("hh",formattedHours).replace("mm",formattedMinutes).replace("ss",formattedSeconds).replace("ms",formattedMs);};return _jsx(Text,Object.assign({},rest,{style:[styles.defaultTimerStyle,style],children:formatTime(time)}));});var styles=StyleSheet.create({defaultTimerStyle:{fontSize:24,textAlign:"left"}});export default Timer;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { TextStyle, StyleProp } from "react-native";
|
|
3
|
-
interface TimerProps {
|
|
2
|
+
import { TextStyle, StyleProp, TextProps } from "react-native";
|
|
3
|
+
interface TimerProps extends TextProps {
|
|
4
4
|
style?: StyleProp<TextStyle>;
|
|
5
5
|
initialTime?: number;
|
|
6
6
|
updateInterval?: number;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useState, useEffect, useRef, useImperativeHandle, forwardRef, } from "react";
|
|
2
|
-
import { Text, StyleSheet } from "react-native";
|
|
3
|
-
const Timer = forwardRef(({ style, initialTime, updateInterval = 1000, format = "mm:ss", onTimerChange, onTimerEnd, countDirection = "up", timerEndTime, }, ref) => {
|
|
4
|
-
const defaultInitialTime =
|
|
2
|
+
import { Text, StyleSheet, } from "react-native";
|
|
3
|
+
const Timer = forwardRef(({ style, initialTime, updateInterval = 1000, format = "mm:ss", onTimerChange, onTimerEnd, countDirection = "up", timerEndTime, ...rest }, ref) => {
|
|
4
|
+
const defaultInitialTime = 0;
|
|
5
5
|
const [time, setTime] = useState(initialTime !== null && initialTime !== void 0 ? initialTime : defaultInitialTime);
|
|
6
6
|
const timerRef = useRef(null);
|
|
7
7
|
useEffect(() => {
|
|
@@ -24,7 +24,10 @@ const Timer = forwardRef(({ style, initialTime, updateInterval = 1000, format =
|
|
|
24
24
|
// Count down
|
|
25
25
|
if (newTime <= 0 && countDirection === "down") {
|
|
26
26
|
clearTimer();
|
|
27
|
-
|
|
27
|
+
// Delay the onTimerEnd callback to ensure it triggers after the final time update
|
|
28
|
+
setTimeout(() => {
|
|
29
|
+
onTimerEnd === null || onTimerEnd === void 0 ? void 0 : onTimerEnd();
|
|
30
|
+
}, updateInterval);
|
|
28
31
|
return 0;
|
|
29
32
|
}
|
|
30
33
|
// Count up
|
|
@@ -32,7 +35,10 @@ const Timer = forwardRef(({ style, initialTime, updateInterval = 1000, format =
|
|
|
32
35
|
timerEndTime !== undefined &&
|
|
33
36
|
newTime >= timerEndTime) {
|
|
34
37
|
clearTimer();
|
|
35
|
-
|
|
38
|
+
// Delay the onTimerEnd callback to ensure it triggers after the final time update
|
|
39
|
+
setTimeout(() => {
|
|
40
|
+
onTimerEnd === null || onTimerEnd === void 0 ? void 0 : onTimerEnd();
|
|
41
|
+
}, updateInterval);
|
|
36
42
|
return timerEndTime;
|
|
37
43
|
}
|
|
38
44
|
return newTime;
|
|
@@ -69,12 +75,12 @@ const Timer = forwardRef(({ style, initialTime, updateInterval = 1000, format =
|
|
|
69
75
|
.replace("ss", formattedSeconds)
|
|
70
76
|
.replace("ms", formattedMs);
|
|
71
77
|
};
|
|
72
|
-
return (React.createElement(Text, { style: [styles.defaultTimerStyle, style] }, formatTime(time)));
|
|
78
|
+
return (React.createElement(Text, { ...rest, style: [styles.defaultTimerStyle, style] }, formatTime(time)));
|
|
73
79
|
});
|
|
74
80
|
const styles = StyleSheet.create({
|
|
75
81
|
defaultTimerStyle: {
|
|
76
82
|
fontSize: 24,
|
|
77
|
-
textAlign: "
|
|
83
|
+
textAlign: "left",
|
|
78
84
|
},
|
|
79
85
|
});
|
|
80
86
|
export default Timer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Timer.js","sourceRoot":"","sources":["../../../../src/components/Timer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,QAAQ,EACR,SAAS,EACT,MAAM,EACN,mBAAmB,EACnB,UAAU,GACX,MAAM,OAAO,CAAC;AACf,OAAO,
|
|
1
|
+
{"version":3,"file":"Timer.js","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