Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions Components/Callout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React, { useMemo } from 'react';
import { ColorValue, StyleSheet, View } from 'react-native';
import { useTheme } from '../Themes/ThemeContextProvider';

type CalloutProps = {
title: React.ReactNode;
children: React.ReactNode;
backgroundColor?: ColorValue;
borderColor?: ColorValue;
padding?: number;
};

function Callout(props: CalloutProps) {
const { currentTheme } = useTheme();

// This rule is needed because style sheets in a useMemo are not
// detected by eslint normally.
/* eslint react-native/no-unused-styles: off */
const styles = useMemo(
() =>
StyleSheet.create({
container: {
backgroundColor: props.backgroundColor ?? currentTheme.background,
borderColor: props.borderColor,
borderRadius: 8,
borderWidth: props.borderColor ? 1 : 0,
padding: props.padding ?? 8,
width: '100%',
},
title: {
alignItems: 'center',
flexDirection: 'row',
marginBottom: 4,
},
}),
[props.backgroundColor, props.borderColor, props.padding, currentTheme],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think useMemo is used to save computations by caching the dependencies passed into it, but I don't think that things like background color or current theme will change that frequently for it to really need useMemo. But it's technically an optimization, so it doesn't cause problems

);
return (
<View style={styles.container}>
<View style={styles.title}>{props.title}</View>
<View>{props.children}</View>
</View>
);
}

export default Callout;
53 changes: 53 additions & 0 deletions Components/WarningCallout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import MaterialDesignIcons from '@react-native-vector-icons/material-design-icons';
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Colors } from '../Themes/Colors';
import { useTheme } from '../Themes/ThemeContextProvider';
import Callout from './Callout';

type WarningCalloutProps = {
titleText: string;
body: React.ReactNode;
padding?: number;
};

function WarningCallout(props: WarningCalloutProps) {
const { currentTheme } = useTheme();

const backgroundColor = currentTheme.warningSubtle;
const borderColor = Colors.warningLightMuted;

return (
<Callout
title={
<View style={styles.header}>
<MaterialDesignIcons
name="alert-circle-outline"
color={currentTheme.onSurface}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This icon is not visible on dark mode but is visible on light mode, I think it has something to do with the onSurface color for dark mode

size={24}
/>
<Text style={styles.title}>{props.titleText}</Text>
</View>
}
backgroundColor={backgroundColor}
borderColor={borderColor}
padding={props.padding}
>
{props.body}
</Callout>
);
}

export default WarningCallout;

const styles = StyleSheet.create({
header: {
alignItems: 'center',
flexDirection: 'row',
},
title: {
fontSize: 18,
fontWeight: '600',
marginLeft: 8,
},
});
3 changes: 3 additions & 0 deletions Themes/Themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type Theme = {
surfaceContainerHigh: ColorValue;
surfaceContainerHighest: ColorValue;
success: ColorValue;
warningSubtle: ColorValue;
};

export const LightMode: Theme = {
Expand Down Expand Up @@ -76,6 +77,7 @@ export const LightMode: Theme = {
surfaceContainerHigh: Colors.surfaceContainerHighLight,
surfaceContainerHighest: Colors.surfaceContainerHighestLight,
success: Colors.success,
warningSubtle: Colors.warningLightSubtle,
};

export const DarkMode: Theme = {
Expand Down Expand Up @@ -115,4 +117,5 @@ export const DarkMode: Theme = {
surfaceContainerHigh: Colors.surfaceContainerHighDark,
surfaceContainerHighest: Colors.surfaceContainerHighestDark,
success: Colors.success,
warningSubtle: Colors.warningDarkSubtle,
};