-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: useBooleanWithHaptics, fix some other stuff
- Loading branch information
1 parent
00b70be
commit 82dad4b
Showing
10 changed files
with
78 additions
and
70 deletions.
There are no files selected for viewing
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,25 @@ | ||
import * as Haptics from 'expo-haptics' | ||
import { useCallback, useState } from 'react' | ||
import { Platform } from 'react-native' | ||
|
||
export function useBooleanWithHaptics(initialValue = false) { | ||
const [value, setValue] = useState(initialValue) | ||
|
||
const on = useCallback(() => { | ||
if (Platform.OS === 'ios') { | ||
void Haptics.selectionAsync() | ||
} | ||
setValue(true) | ||
}, []) | ||
|
||
const off = useCallback(() => { | ||
if (Platform.OS === 'ios') { | ||
void Haptics.selectionAsync() | ||
} | ||
setValue(false) | ||
}, []) | ||
|
||
return [value, on, off] as const | ||
} | ||
|
||
export default useBooleanWithHaptics |
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,25 +1,5 @@ | ||
import * as Haptics from 'expo-haptics' | ||
import { useCallback, useState } from 'react' | ||
import { Platform } from 'react-native' | ||
import useBoolean from './useBoolean' | ||
|
||
export function useBooleanWithHaptics(initialValue = false) { | ||
const [value, setValue] = useState(initialValue) | ||
export const useBooleanWithHaptics = useBoolean | ||
|
||
const on = useCallback(() => { | ||
if (Platform.OS === 'ios') { | ||
void Haptics.selectionAsync() | ||
} | ||
setValue(true) | ||
}, []) | ||
|
||
const off = useCallback(() => { | ||
if (Platform.OS === 'ios') { | ||
void Haptics.selectionAsync() | ||
} | ||
setValue(false) | ||
}, []) | ||
|
||
return [value, on, off] as const | ||
} | ||
|
||
export default useBooleanWithHaptics | ||
export default useBoolean |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { useCallback, useContext } from 'react' | ||
import { Alert } from 'react-native' | ||
|
||
import StringsContext from '../contexts/Strings' | ||
|
||
export function useConfirm() { | ||
const { Cancel, OK } = useContext(StringsContext) | ||
|
||
return useCallback(async (title: string, message?: string) => new Promise<boolean>((resolve) => { | ||
Alert.alert( | ||
title, | ||
message, | ||
[ | ||
{ text: Cancel, onPress: () => resolve(false), style: 'cancel' }, | ||
{ text: OK, onPress: () => resolve(true) }, | ||
], | ||
{ cancelable: false }, | ||
) | ||
}), [Cancel, OK]) | ||
} | ||
|
||
export default useConfirm |
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,22 +1,10 @@ | ||
import { useCallback, useContext } from 'react' | ||
import { Alert } from 'react-native' | ||
|
||
import StringsContext from '../contexts/Strings' | ||
const confirm = async (title: string, message?: string) => new Promise<boolean>((resolve) => { | ||
// eslint-disable-next-line no-alert | ||
resolve(window.confirm([title, message].filter(Boolean).join('\n'))) | ||
}) | ||
|
||
export function useConfirm() { | ||
const { Cancel, OK } = useContext(StringsContext) | ||
|
||
return useCallback(async (title: string, message?: string) => new Promise<boolean>((resolve) => { | ||
Alert.alert( | ||
title, | ||
message, | ||
[ | ||
{ text: Cancel, onPress: () => resolve(false), style: 'cancel' }, | ||
{ text: OK, onPress: () => resolve(true) }, | ||
], | ||
{ cancelable: false }, | ||
) | ||
}), [Cancel, OK]) | ||
return confirm | ||
} | ||
|
||
export default useConfirm |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useCallback, useState } from 'react' | ||
|
||
import doHaptics from '../utils/doHaptics' | ||
|
||
export function useToggleWithHaptics(initialValue = false, enableHaptics: boolean | undefined = undefined) { | ||
const [value, setValue] = useState(initialValue) | ||
|
||
const toggle = useCallback(() => { | ||
void doHaptics(enableHaptics) | ||
setValue((prev) => !prev) | ||
}, [enableHaptics]) | ||
|
||
return [value, toggle] as const | ||
} | ||
|
||
export default useToggleWithHaptics |
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,16 +1,5 @@ | ||
import { useCallback, useState } from 'react' | ||
import useToggle from './useToggle' | ||
|
||
import doHaptics from '../utils/doHaptics' | ||
export const useToggleWithHaptics = useToggle | ||
|
||
export function useToggleWithHaptics(initialValue = false, enableHaptics: boolean | undefined = undefined) { | ||
const [value, setValue] = useState(initialValue) | ||
|
||
const toggle = useCallback(() => { | ||
void doHaptics(enableHaptics) | ||
setValue((prev) => !prev) | ||
}, [enableHaptics]) | ||
|
||
return [value, toggle] as const | ||
} | ||
|
||
export default useToggleWithHaptics | ||
export default useToggle |
This file was deleted.
Oops, something went wrong.