Skip to content

Commit 6d9ebe6

Browse files
Merge pull request #134 from SimformSolutionsPvtLtd/fix/UNT-T30467_seek_on_tap_functionality
fix(UNT-T30467): seek on tap functionality
2 parents 1e538d0 + 7dc0cf8 commit 6d9ebe6

File tree

5 files changed

+45
-5
lines changed

5 files changed

+45
-5
lines changed

example/src/App.tsx

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,17 @@ const RenderListItem = React.memo(
6868
const handleButtonAction = () => {
6969
if (playerState === PlayerState.stopped) {
7070
setCurrentPlaying(item.path);
71+
} else if (playerState === PlayerState.playing) {
72+
ref.current?.pausePlayer();
7173
} else {
72-
setCurrentPlaying('');
74+
ref.current?.resumePlayer();
7375
}
7476
};
7577

78+
const handleStopAction = () => {
79+
setCurrentPlaying('');
80+
};
81+
7682
useEffect(() => {
7783
if (currentPlaying !== item.path) {
7884
ref.current?.stopPlayer();
@@ -90,19 +96,38 @@ const RenderListItem = React.memo(
9096
onPress={handleButtonAction}
9197
style={styles.playBackControlPressable}>
9298
{isLoading ? (
93-
<ActivityIndicator color={'#FF0000'} />
99+
<ActivityIndicator color={'#FFFFFF'} />
94100
) : (
95101
<FastImage
96102
source={
97-
playerState === PlayerState.stopped
103+
playerState !== PlayerState.playing
98104
? Icons.play
99-
: Icons.stop
105+
: Icons.pause
100106
}
101107
style={styles.buttonImage}
102108
resizeMode="contain"
103109
/>
104110
)}
105111
</Pressable>
112+
<Pressable
113+
disabled={PlayerState.stopped == playerState}
114+
onPress={handleStopAction}
115+
style={styles.playBackControlPressable}>
116+
{isLoading ? (
117+
<ActivityIndicator color={'#FFFFFF'} />
118+
) : (
119+
<FastImage
120+
source={Icons.stop}
121+
style={[
122+
styles.stopButton,
123+
{
124+
opacity: playerState === PlayerState.stopped ? 0.5 : 1,
125+
},
126+
]}
127+
resizeMode="contain"
128+
/>
129+
)}
130+
</Pressable>
106131
<Waveform
107132
containerStyle={styles.staticWaveformView}
108133
mode="static"

example/src/assets/icons/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export const Icons = {
55
mic: require('./mic.png'),
66
logo: require('./logo.png'),
77
delete: require('./delete.png'),
8+
pause: require('./pause.png'),
89
};

example/src/assets/icons/pause.png

10.5 KB
Loading

example/src/styles.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ const styles = (params: StyleSheetParams = {}) =>
5454
tintColor: Colors.white,
5555
alignSelf: 'flex-end',
5656
},
57+
stopButton: {
58+
height: scale(22),
59+
width: scale(22),
60+
alignSelf: 'center',
61+
},
5762
pinkButtonImage: {
5863
height: scale(22),
5964
width: scale(22),

src/components/Waveform/Waveform.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export const Waveform = forwardRef<IWaveformRef, IWaveform>((props, ref) => {
6767
const viewRef = useRef<View>(null);
6868
const scrollRef = useRef<ScrollView>(null);
6969
const isLayoutCalculated = useRef<boolean>(false);
70+
const isAutoPaused = useRef<boolean>(false);
7071
const [waveform, setWaveform] = useState<number[]>([]);
7172
const [viewLayout, setViewLayout] = useState<LayoutRectangle | null>(null);
7273
const [seekPosition, setSeekPosition] = useState<NativeTouchEvent | null>(
@@ -518,11 +519,14 @@ export const Waveform = forwardRef<IWaveformRef, IWaveform>((props, ref) => {
518519
if (panMoving) {
519520
if (playerState === PlayerState.playing) {
520521
pausePlayerAction();
522+
isAutoPaused.current = true;
521523
}
522524
} else {
523-
if (playerState === PlayerState.paused) {
525+
if (playerState === PlayerState.paused && isAutoPaused.current) {
524526
startPlayerAction();
525527
}
528+
529+
isAutoPaused.current = false;
526530
}
527531
// eslint-disable-next-line react-hooks/exhaustive-deps
528532
}, [panMoving]);
@@ -559,6 +563,11 @@ export const Waveform = forwardRef<IWaveformRef, IWaveform>((props, ref) => {
559563
(onPanStateChange as Function)(false);
560564
setPanMoving(false);
561565
},
566+
onPanResponderRelease: e => {
567+
setSeekPosition(e.nativeEvent);
568+
(onPanStateChange as Function)(false);
569+
setPanMoving(false);
570+
},
562571
})
563572
).current;
564573

0 commit comments

Comments
 (0)