-
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from huextrat/fix/types
fix(ts): export types
- Loading branch information
Showing
8 changed files
with
37 additions
and
136 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,14 @@ | ||
import type { TurboModule } from 'react-native'; | ||
import { TurboModuleRegistry } from 'react-native'; | ||
|
||
export interface Spec extends TurboModule { | ||
trigger( | ||
type: string, | ||
options?: { | ||
enableVibrateFallback?: boolean; | ||
ignoreAndroidSystemSettings?: boolean; | ||
}, | ||
): void; | ||
} | ||
|
||
export default TurboModuleRegistry.getEnforcing<Spec>("RNHapticFeedback"); |
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 |
---|---|---|
@@ -1,49 +1,26 @@ | ||
import { NativeModules } from "react-native"; | ||
import NativeHapticFeedback from './codegenSpec/NativeHapticFeedback'; | ||
import { HapticFeedbackTypes } from "./types"; | ||
import type { HapticOptions } from "./types"; | ||
|
||
import type { Spec } from "./NativeHapticFeedback"; | ||
export * from "./types"; | ||
|
||
const defaultOptions = { | ||
enableVibrateFallback: false, | ||
ignoreAndroidSystemSettings: false, | ||
}; | ||
|
||
class RNReactNativeHapticFeedback { | ||
static trigger = ( | ||
const RNHapticFeedback = { | ||
trigger( | ||
type: | ||
| keyof typeof HapticFeedbackTypes | ||
| HapticFeedbackTypes = HapticFeedbackTypes.selection, | ||
options: HapticOptions = {}, | ||
) => { | ||
const triggerOptions = createTriggerOptions(options); | ||
|
||
) { | ||
try { | ||
const isTurboModuleEnabled = global.__turboModuleProxy != null; | ||
const hapticFeedback = isTurboModuleEnabled | ||
? (require("./NativeHapticFeedback").default as Spec) | ||
: NativeModules.RNHapticFeedback; | ||
|
||
hapticFeedback.trigger(type, triggerOptions); | ||
NativeHapticFeedback.trigger(type, { ...defaultOptions, ...options }); | ||
} catch { | ||
console.warn("RNReactNativeHapticFeedback is not available"); | ||
} | ||
}; | ||
} | ||
|
||
const createTriggerOptions = (options: HapticOptions) => { | ||
// if options is a boolean we're using an api <=1.6 and we should pass use it to set the enableVibrateFallback option | ||
if (typeof options === "boolean") { | ||
return { | ||
...defaultOptions, | ||
enableVibrateFallback: options, | ||
}; | ||
} else { | ||
return { ...defaultOptions, ...options }; | ||
} | ||
}; | ||
|
||
export const trigger = RNReactNativeHapticFeedback.trigger; | ||
} | ||
|
||
export default RNReactNativeHapticFeedback; | ||
export const { trigger } = RNHapticFeedback; | ||
export default RNHapticFeedback; |
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