Skip to content

Commit

Permalink
fix: add stop
Browse files Browse the repository at this point in the history
  • Loading branch information
gtokman committed Nov 11, 2023
1 parent c05340d commit bffe5b2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
11 changes: 10 additions & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';

import type { HapticType } from '@candlefinance/haptics';
import { haptic, hapticWithPattern, play } from '@candlefinance/haptics';
import { haptic, hapticWithPattern, play, stop } from '@candlefinance/haptics';
import { Pressable, StyleSheet, Text, View } from 'react-native';

export default function App() {
Expand Down Expand Up @@ -75,6 +75,15 @@ export default function App() {
>
<Text>Play File</Text>
</Pressable>
<Pressable
style={styles.button}
onPress={() => {
console.log('hapticWithPatternFile');
stop();
}}
>
<Text>stop File</Text>
</Pressable>
</View>
);
}
Expand Down
1 change: 1 addition & 0 deletions ios/Haptics.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ @interface RCT_EXTERN_MODULE(Haptics, NSObject)
RCT_EXTERN_METHOD(haptic:(NSString *)type)
RCT_EXTERN_METHOD(hapticWithPattern:(NSArray<NSString *> *)pattern)
RCT_EXTERN_METHOD(play:(nonnull NSString *)fileName loop:(nonnull BOOL)loop)
RCT_EXTERN_METHOD(stop)

+ (BOOL)requiresMainQueueSetup
{
Expand Down
5 changes: 5 additions & 0 deletions ios/Haptics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ class Haptics: NSObject {
func play(fileName: String, loop: Bool) {
Vibrator.shared.startHaptic(named: fileName, loop: loop)
}

@objc(stop)
func stop() {
Vibrator.shared.stopHaptic()
}
}
8 changes: 8 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,11 @@ export function play(fileName: string, loop: boolean = false) {
}
Haptics.play(fileName, loop);
}

export function stop() {
if (Platform.OS === 'android') {
console.log('Haptics is not supported on Android');
return;
}
Haptics.stop();
}

0 comments on commit bffe5b2

Please sign in to comment.