This repository has been archived by the owner on Oct 28, 2023. It is now read-only.
-
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.
Merge pull request #14 from Team488/update-babel
Fix build issues and refactor event button components
- Loading branch information
Showing
16 changed files
with
2,367 additions
and
776 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
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,33 @@ | ||
import {StyleSheet} from 'react-native'; | ||
import { | ||
Button, | ||
Text, | ||
} from 'native-base'; | ||
import React from 'react'; | ||
import { useOnEvent } from './OnEventContext'; | ||
import { EventCode } from 'src/record/Events'; | ||
|
||
const styles = StyleSheet.create({ | ||
eventButton: { | ||
margin: 5, | ||
alignSelf: 'center', | ||
}, | ||
}); | ||
|
||
export const EventButton = ({ | ||
eventCode, | ||
label, | ||
}: { | ||
eventCode: EventCode; | ||
label: string; | ||
}) => { | ||
const onEvent = useOnEvent(); | ||
return ( | ||
<Button | ||
large | ||
style={styles.eventButton} | ||
onPress={() => onEvent({code: eventCode, timestamp: Date.now()})}> | ||
<Text>{label}</Text> | ||
</Button> | ||
); | ||
}; |
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,61 @@ | ||
import {StyleSheet} from 'react-native'; | ||
import { | ||
ActionSheet, | ||
Button, | ||
Text, | ||
} from 'native-base'; | ||
import React from 'react'; | ||
|
||
import { EventCode } from 'src/record/Events'; | ||
import { OnEventHandler, useOnEvent } from './OnEventContext'; | ||
|
||
type EventOptions = Record<string, EventCode>; | ||
|
||
const styles = StyleSheet.create({ | ||
eventButton: { | ||
margin: 5, | ||
alignSelf: 'center', | ||
}, | ||
}); | ||
|
||
const showDialog = (title: string, options: EventOptions, emitEvent: OnEventHandler) => { | ||
const cancelIdx = Object.keys(options).length; | ||
const timestamp = Date.now(); | ||
|
||
ActionSheet.show( | ||
{ | ||
options: [...Object.keys(options), "Cancel"], | ||
cancelButtonIndex: cancelIdx, | ||
title, | ||
}, | ||
buttonIndex => { | ||
if (buttonIndex === cancelIdx) { | ||
return; | ||
} | ||
const label = Object.keys(options)[buttonIndex]; | ||
const code = options[label]; | ||
|
||
emitEvent({ timestamp, code }); | ||
} | ||
) | ||
} | ||
|
||
export const ModalEventButton = ({ | ||
dialogMessage, | ||
eventOptions, | ||
label, | ||
}: { | ||
dialogMessage: string, | ||
eventOptions: EventOptions; | ||
label: string; | ||
}) => { | ||
const emitEvent = useOnEvent(); | ||
return ( | ||
<Button | ||
large | ||
style={styles.eventButton} | ||
onPress={() => showDialog(dialogMessage, eventOptions, emitEvent)}> | ||
<Text>{label}</Text> | ||
</Button> | ||
); | ||
}; |
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 React from 'react'; | ||
import { EventCode } from 'src/record/Events'; | ||
|
||
export interface TimedEvent { | ||
timestamp: number, | ||
code: EventCode | ||
} | ||
|
||
export type OnEventHandler = (event: TimedEvent) => void; | ||
|
||
export const OnEventContext = React.createContext((event: TimedEvent) => {}); | ||
|
||
export const useOnEvent: () => OnEventHandler = () => { | ||
const context = React.useContext(OnEventContext); | ||
return context; | ||
}; |
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
Oops, something went wrong.