-
-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: refactoring logic of withAutoFillData, Add onProgressChange valu…
…e boundary fix #158
- Loading branch information
Showing
4 changed files
with
127 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { DATA_LENGTH } from 'src/constants'; | ||
|
||
const { SINGLE_ITEM, DOUBLE_ITEM } = DATA_LENGTH; | ||
|
||
function isAutoFillData(params: { autoFillData: boolean; loop: boolean }) { | ||
'worklet'; | ||
return !!params.loop && !!params.autoFillData; | ||
} | ||
|
||
type BaseParams<T extends object = {}> = { | ||
autoFillData: boolean; | ||
loop: boolean; | ||
} & T; | ||
|
||
export function computedOffsetXValueWithAutoFillData( | ||
params: BaseParams<{ | ||
rawDataLength: number; | ||
value: number; | ||
size: number; | ||
}> | ||
) { | ||
'worklet'; | ||
|
||
const { rawDataLength, value, size, loop, autoFillData } = params; | ||
|
||
if (isAutoFillData({ loop, autoFillData })) { | ||
switch (rawDataLength) { | ||
case SINGLE_ITEM: | ||
return value % size; | ||
case DOUBLE_ITEM: | ||
return value % (size * 2); | ||
} | ||
} | ||
|
||
return value; | ||
} | ||
|
||
export function computedRealIndexWithAutoFillData( | ||
params: BaseParams<{ | ||
index: number; | ||
dataLength: number; | ||
}> | ||
) { | ||
const { index, dataLength, loop, autoFillData } = params; | ||
|
||
if (isAutoFillData({ loop, autoFillData })) { | ||
switch (dataLength) { | ||
case SINGLE_ITEM: | ||
return index % 1; | ||
case DOUBLE_ITEM: | ||
return index % 2; | ||
} | ||
} | ||
|
||
return index; | ||
} | ||
|
||
export function computedFillDataWithAutoFillData<T>( | ||
params: BaseParams<{ | ||
data: T[]; | ||
dataLength: number; | ||
}> | ||
): T[] { | ||
const { data, loop, autoFillData, dataLength } = params; | ||
|
||
if (isAutoFillData({ loop, autoFillData })) { | ||
switch (dataLength) { | ||
case SINGLE_ITEM: | ||
return [data[0], data[0], data[0]]; | ||
case DOUBLE_ITEM: | ||
return [data[0], data[1], data[0], data[1]]; | ||
} | ||
} | ||
|
||
return data; | ||
} |