-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
257 additions
and
39 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,107 @@ | ||
import * as React from 'react'; | ||
import { | ||
Appbar, | ||
Drawer, | ||
IconButton, | ||
Portal, | ||
Provider, | ||
} from 'react-native-paper'; | ||
import { useAppConfig, useAppConfigList } from '../hooks/useAppConfig'; | ||
import { Modal, NativeEventEmitter, View } from 'react-native'; | ||
import { createStyles } from './BrandConfigProvider/styles/createStyles'; | ||
import { useStyles } from '../hooks/useStyles'; | ||
import { useIcons } from './BrandConfigProvider'; | ||
|
||
const eventEmitter = new NativeEventEmitter({ | ||
addListener: () => {}, | ||
removeListeners: () => {}, | ||
}); | ||
|
||
const showAppConfigSwitcher = 'showAppConfigSwitcher'; | ||
|
||
export const emitShowAppConfigSwitcher = () => | ||
eventEmitter.emit(showAppConfigSwitcher); | ||
|
||
const AppConfigSwitcher = () => { | ||
const configs = useAppConfigList(); | ||
const { setAppConfigId, appConfigId } = useAppConfig(); | ||
const [active, setActive] = React.useState(appConfigId); | ||
const [visible, setVisible] = React.useState(false); | ||
|
||
const hideModal = () => setVisible(false); | ||
const { styles } = useStyles(defaultStyles); | ||
const { ArrowLeft } = useIcons(); | ||
|
||
React.useEffect(() => { | ||
const subscription = eventEmitter.addListener(showAppConfigSwitcher, () => { | ||
setVisible(true); | ||
}); | ||
|
||
return () => { | ||
subscription.remove(); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<Provider> | ||
<Portal> | ||
<Modal | ||
visible={visible} | ||
onDismiss={hideModal} | ||
animationType={'slide'} | ||
style={styles.modal} | ||
> | ||
<View style={styles.container}> | ||
<Appbar.Header style={styles.header}> | ||
<IconButton onPress={() => hideModal()} icon={ArrowLeft} /> | ||
</Appbar.Header> | ||
<Drawer.Section | ||
title="Adaptive Experiences: Tailored by Cohort" | ||
showDivider={true} | ||
titleMaxFontSizeMultiplier={4} | ||
> | ||
{configs?.map((config) => ( | ||
<Drawer.Item | ||
key={config.id} | ||
label={config.name} | ||
active={active === config.id} | ||
style={styles.itemText} | ||
onPress={() => { | ||
setActive(config.id); | ||
setAppConfigId(config.id); | ||
setVisible(false); | ||
}} | ||
/> | ||
))} | ||
</Drawer.Section> | ||
</View> | ||
</Modal> | ||
</Portal> | ||
</Provider> | ||
); | ||
}; | ||
|
||
export default AppConfigSwitcher; | ||
|
||
const defaultStyles = createStyles('AppConfigSwitcher', (theme) => ({ | ||
modal: { | ||
marginTop: 100, | ||
marginBottom: 0, | ||
}, | ||
container: { | ||
height: '100%', | ||
flex: 1, | ||
}, | ||
header: {}, | ||
titleText: { | ||
...theme.fonts.headlineMedium, | ||
}, | ||
itemText: {}, | ||
})); | ||
|
||
declare module '@styles' { | ||
interface ComponentStyles | ||
extends ComponentNamedStyles<typeof defaultStyles> {} | ||
} | ||
|
||
export type AppConfigSwitcher = NamedStylesProp<typeof defaultStyles>; |
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,31 @@ | ||
import React from 'react'; | ||
import { IconButton } from 'react-native-paper'; | ||
import { useIcons } from './BrandConfigProvider/icons/IconProvider'; | ||
import { emitShowAppConfigSwitcher } from './AppConfigSwitcher'; | ||
import { createStyles } from './BrandConfigProvider/styles/createStyles'; | ||
import { useStyles } from '../hooks/useStyles'; | ||
|
||
const AppConfigSwitcherButton = () => { | ||
const { Menu } = useIcons(); | ||
const { styles } = useStyles(defaultStyles); | ||
return ( | ||
<IconButton | ||
onPress={emitShowAppConfigSwitcher} | ||
icon={Menu} | ||
style={styles.button} | ||
/> | ||
); | ||
}; | ||
|
||
export default AppConfigSwitcherButton; | ||
|
||
const defaultStyles = createStyles('AppConfigSwitcherButton', () => ({ | ||
button: {}, | ||
})); | ||
|
||
declare module '@styles' { | ||
interface ComponentStyles | ||
extends ComponentNamedStyles<typeof defaultStyles> {} | ||
} | ||
|
||
export type AppConfigSwitcher = NamedStylesProp<typeof defaultStyles>; |
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