Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/containers/ActionSheet/Handle.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { forwardRef, type ComponentType, type Ref } from 'react';
import { forwardRef } from 'react';
import { View } from 'react-native';
import { RectButton } from 'react-native-gesture-handler';

import { RectButton } from '~/containers/GestureButtons';
import styles from './styles';
import { themes } from '~/lib/constants/colors';
import { useTheme } from '~/theme';
Expand All @@ -13,7 +13,7 @@ export const Handle = forwardRef<View, { onPress: () => void }>(({ onPress }, re
// We should use RectButton from gesture-handler to avoid issues with the keyboard
return (
<RectButton
ref={ref as Ref<ComponentType>}
ref={ref}
onPress={onPress}
style={styles.handle}
testID='action-sheet-handle'
Expand Down
12 changes: 8 additions & 4 deletions app/containers/AudioPlayer/Seek.test.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import { act, render, renderHook } from '@testing-library/react-native';
import { Gesture, State } from 'react-native-gesture-handler';
import { State, usePanGesture } from 'react-native-gesture-handler';
import { fireGestureHandler } from 'react-native-gesture-handler/jest-utils';
import { useSharedValue } from 'react-native-reanimated';

import Seek from './Seek';

jest.mock('~/theme', () => ({ useTheme: () => ({ colors: {} }) }));
jest.mock('react-native-gesture-handler', () => {
const actual = jest.requireActual('react-native-gesture-handler');
return { ...actual, usePanGesture: jest.fn(actual.usePanGesture) };
});

const setup = () => {
const pan = jest.spyOn(Gesture, 'Pan');
const { result } = renderHook(() => ({ currentTime: useSharedValue(30), duration: useSharedValue(120) }));
const { currentTime, duration } = result.current;
const onChangeTime = jest.fn();
render(<Seek currentTime={currentTime} duration={duration} loaded onChangeTime={onChangeTime} />);
return { gesture: pan.mock.results[0].value, currentTime, onChangeTime };
const { results } = jest.mocked(usePanGesture).mock;
return { gesture: results[results.length - 1].value, currentTime, onChangeTime };
};

afterEach(() => jest.restoreAllMocks());
afterEach(() => jest.clearAllMocks());

test('a tap that never starts dragging preserves the paused position', async () => {
const { gesture, currentTime, onChangeTime } = setup();
Expand Down
27 changes: 14 additions & 13 deletions app/containers/AudioPlayer/Seek.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type LayoutChangeEvent, View, TextInput, type TextInputProps, TouchableNativeFeedback } from 'react-native';
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
import { GestureDetector, usePanGesture } from 'react-native-gesture-handler';
import Animated, {
type SharedValue,
useAnimatedProps,
Expand Down Expand Up @@ -65,31 +65,32 @@ const Seek = ({ currentTime, duration, loaded = false, onChangeTime }: ISeek) =>
maxWidth.value = width;
};

const panGesture = Gesture.Pan()
.enabled(loaded)
.activeOffsetX([-ACTIVE_OFFSET_X, ACTIVE_OFFSET_X])
.onStart(() => {
const panGesture = usePanGesture({
enabled: loaded,
activeOffsetX: [-ACTIVE_OFFSET_X, ACTIVE_OFFSET_X],
onActivate: () => {
isPanning.value = true;
contextX.value = translateX.value;
savedTranslateX.value = translateX.value;
savedCurrentTime.value = currentTime.value;
scale.value = withTiming(1.3, { duration: 150 });
})
.onUpdate(event => {
},
onUpdate: event => {
const newX = contextX.value + event.translationX;
translateX.value = clamp(newX, 0, maxWidth.value);
})
.onFinalize((_, didSucceed) => {
},
onFinalize: event => {
if (!isPanning.value) return;
isPanning.value = false;
scale.value = withTiming(1, { duration: 150 });
if (didSucceed) {
scheduleOnRN(onChangeTime, currentTime.value);
} else {
if (event.canceled) {
translateX.value = savedTranslateX.value;
currentTime.value = savedCurrentTime.value;
} else {
scheduleOnRN(onChangeTime, currentTime.value);
}
});
}
});

useDerivedValue(() => {
if (isPanning.value) {
Expand Down
99 changes: 51 additions & 48 deletions app/containers/Avatar/__snapshots__/Avatar.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -926,60 +926,63 @@ exports[`Story Snapshots: Touchable should match snapshot 1`] = `
]
}
>
<RNGestureHandlerButton
activeOpacity={1}
<View
accessibilityState={
{
"busy": undefined,
"checked": undefined,
"disabled": undefined,
"expanded": undefined,
"selected": undefined,
}
}
accessibilityValue={
{
"max": undefined,
"min": undefined,
"now": undefined,
"text": undefined,
}
}
accessible={true}
activeUnderlayOpacity={1}
animationDuration={0}
collapsable={false}
delayLongPress={600}
enabled={true}
handlerTag={-1}
handlerType="NativeViewGestureHandler"
innerRef={null}
onActiveStateChange={[Function]}
onGestureHandlerEvent={[Function]}
onGestureHandlerStateChange={[Function]}
onPress={[Function]}
rippleColor="#E4E7EA"
focusable={true}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
[
{
"backgroundColor": undefined,
"borderRadius": undefined,
"margin": undefined,
"marginBottom": undefined,
"marginEnd": undefined,
"marginHorizontal": undefined,
"marginLeft": undefined,
"marginRight": undefined,
"marginStart": undefined,
"marginTop": undefined,
"marginVertical": undefined,
},
{
"cursor": undefined,
},
[
undefined,
{
"margin": undefined,
"marginBottom": undefined,
"marginEnd": undefined,
"marginHorizontal": undefined,
"marginLeft": undefined,
"marginRight": undefined,
"marginStart": undefined,
"marginTop": undefined,
"marginVertical": undefined,
},
{
"backgroundColor": undefined,
"borderRadius": undefined,
},
],
undefined,
]
}
underlayColor="#E4E7EA"
>
<View
collapsable={false}
style={
{
"backgroundColor": "#E4E7EA",
"borderBottomLeftRadius": undefined,
"borderBottomRightRadius": undefined,
"borderRadius": undefined,
"borderTopLeftRadius": undefined,
"borderTopRightRadius": undefined,
"bottom": 0,
"left": 0,
"opacity": 0,
"position": "absolute",
"right": 0,
"top": 0,
}
}
/>
<View
accessibilityLabel="Avatar's avatar"
accessible={true}
Expand Down Expand Up @@ -1027,7 +1030,7 @@ exports[`Story Snapshots: Touchable should match snapshot 1`] = `
width={56}
/>
</View>
</RNGestureHandlerButton>
</View>
</ExternalKeyboardView>
</View>
`;
Expand Down
2 changes: 1 addition & 1 deletion app/containers/Button/Button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('ButtonTests', () => {
test('disabled button is in disabled state', async () => {
const { findByTestId } = render(<TestButton disabled={true} />);
const button = await findByTestId(testProps.testID);
expect(button.props.enabled).toBe(false);
expect(button).toBeDisabled();
});

test('should trigger onPress function on button press', async () => {
Expand Down
Loading
Loading