Skip to content

Commit

Permalink
feat: add haptics
Browse files Browse the repository at this point in the history
  • Loading branch information
kosmydel committed Aug 24, 2023
1 parent eb5b9d1 commit 3732223
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"expo": "~49.0.8",
"expo-haptics": "~12.4.0",
"expo-status-bar": "~1.6.0",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
19 changes: 19 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { DraggableList, ScaleDecorator } from 'react-native-x-draggable-list';
import type { RenderItemParams } from 'react-native-draggable-flatlist';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import type { Item } from 'src/DraggableList/types';
import * as Haptics from 'expo-haptics';

const COLORS = {
LIST: ['#FAF1E4', '#CEDEBD', '#9EB384'],
Expand Down Expand Up @@ -41,6 +42,8 @@ const getCurrentTime = () => {
return new Date().toLocaleTimeString();
};

const isNative = Platform.OS === 'ios' || Platform.OS === 'android';

export default function App() {
const [items, setItems] = useState(getItems(15));
const [lastEvent, setLastEvent] = useState('Listening for events...');
Expand Down Expand Up @@ -82,9 +85,25 @@ export default function App() {
onDragEnd={({ data }: any) => {
logEvent('onDragEnd');
setItems(data);
if (isNative) {
Haptics.notificationAsync(
Haptics.NotificationFeedbackType.Success
);
}
}}
onDragBegin={() => {
logEvent('onDragBegin');
if (isNative) {
Haptics.notificationAsync(
Haptics.NotificationFeedbackType.Success
);
}
}}
onPlaceholderIndexChange={(index: number) => {
logEvent(`onPlaceholderIndexChange ${index}`);
if (isNative) {
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
}
}}
/>
</SafeAreaView>
Expand Down
5 changes: 5 additions & 0 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3972,6 +3972,11 @@ expo-font@~11.4.0:
dependencies:
fontfaceobserver "^2.1.0"

expo-haptics@~12.4.0:
version "12.4.0"
resolved "https://registry.yarnpkg.com/expo-haptics/-/expo-haptics-12.4.0.tgz#99ad9d6a8eafb219aee022ec1412a998e1c90d71"
integrity sha512-eELhZOO64oJa6AtEUxosatjSENE/tQgF2rVJxDsvRdx8Vgd3uFC+FRoM3nbMVJkxDgAaP3EKOPT1zVM41sNurw==

expo-keep-awake@~12.3.0:
version "12.3.0"
resolved "https://registry.yarnpkg.com/expo-keep-awake/-/expo-keep-awake-12.3.0.tgz#c42449ae19c993274ddc43aafa618792b6aec408"
Expand Down
1 change: 1 addition & 0 deletions src/DraggableList/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export type DraggableListProps = {
renderItem: (params: RenderItemParams<Item>) => React.ReactNode;
onDragEnd?: (params: { data: Item[] }) => void;
onDragBegin?: () => void;
onPlaceholderIndexChange?: (params: { index: number }) => void;
};

0 comments on commit 3732223

Please sign in to comment.