create Alert.tsx and Alert.web.tsx and replace uses (#513)
This commit is contained in:
parent
b00365c196
commit
01410ad4bf
4 changed files with 44 additions and 26 deletions
1
src/view/com/util/Alert.tsx
Normal file
1
src/view/com/util/Alert.tsx
Normal file
|
@ -0,0 +1 @@
|
|||
export {Alert} from 'react-native'
|
23
src/view/com/util/Alert.web.tsx
Normal file
23
src/view/com/util/Alert.web.tsx
Normal file
|
@ -0,0 +1,23 @@
|
|||
import {AlertButton, AlertStatic} from 'react-native'
|
||||
|
||||
class WebAlert implements Pick<AlertStatic, 'alert'> {
|
||||
public alert(title: string, message?: string, buttons?: AlertButton[]): void {
|
||||
if (buttons === undefined || buttons.length === 0) {
|
||||
window.alert([title, message].filter(Boolean).join('\n'))
|
||||
return
|
||||
}
|
||||
|
||||
const result = window.confirm([title, message].filter(Boolean).join('\n'))
|
||||
|
||||
if (result === true) {
|
||||
const confirm = buttons.find(({style}) => style !== 'cancel')
|
||||
confirm?.onPress?.()
|
||||
return
|
||||
}
|
||||
|
||||
const cancel = buttons.find(({style}) => style === 'cancel')
|
||||
cancel?.onPress?.()
|
||||
}
|
||||
}
|
||||
|
||||
export const Alert = new WebAlert()
|
Loading…
Add table
Add a link
Reference in a new issue