Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use theme colors in Banner #2932

Merged
merged 2 commits into from
Oct 19, 2021
Merged
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
19 changes: 15 additions & 4 deletions example/src/Examples/BannerExample.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { View, StyleSheet, Image, Dimensions, Platform } from 'react-native';
import { Banner, FAB } from 'react-native-paper';
import { Banner, FAB, useTheme } from 'react-native-paper';
import ScreenWrapper from '../ScreenWrapper';

const PHOTOS = Array.from({ length: 24 }).map(
Expand All @@ -9,23 +9,34 @@ const PHOTOS = Array.from({ length: 24 }).map(

const BannerExample = () => {
const [visible, setVisible] = React.useState<boolean>(true);
const [useCustomTheme, setUseCustomTheme] = React.useState<boolean>(false);
const defaultTheme = useTheme();
const customTheme = {
...defaultTheme,
colors: {
text: '#fff',
surface: '#09c8e5',
primary: '#121330',
},
};

return (
<>
<ScreenWrapper>
<Banner
actions={[
{
label: 'Fix it',
onPress: () => setVisible(false),
label: `Set ${useCustomTheme ? 'default' : 'custom'} theme`,
onPress: () => setUseCustomTheme(!useCustomTheme),
},
{
label: 'Learn more',
label: 'Fix it',
onPress: () => setVisible(false),
},
]}
icon={require('../../assets/images/email-icon.png')}
visible={visible}
theme={useCustomTheme ? customTheme : defaultTheme}
>
Two line text string with two actions. One to two lines is preferable
on mobile.
Expand Down
6 changes: 5 additions & 1 deletion src/components/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ const Banner = ({
<Surface
{...rest}
style={[styles.container, shadow(ELEVATION) as ViewStyle, style]}
theme={theme}
>
<View style={[styles.wrapper, contentStyle]}>
<Animated.View style={{ height }} />
Expand All @@ -197,7 +198,9 @@ const Banner = ({
<Icon source={icon} size={40} />
</View>
) : null}
<Text style={styles.message}>{children}</Text>
<Text style={[styles.message, { color: theme.colors.text }]}>
{children}
</Text>
</View>
<View style={styles.actions}>
{actions.map(({ label, ...others }, i) => (
Expand All @@ -206,6 +209,7 @@ const Banner = ({
compact
mode="text"
style={styles.button}
color={theme.colors.primary}
{...others}
>
{label}
Expand Down
22 changes: 22 additions & 0 deletions src/components/__tests__/Banner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,25 @@ it('renders visible banner, with action buttons and with image', () => {

expect(tree).toMatchSnapshot();
});

it('render visible banner, with custom theme', () => {
const tree = renderer
.create(
<Banner
visible
theme={{
colors: {
text: '#00f',
surface: '#ccc',
primary: '#043',
},
}}
actions={[{ label: 'first', onPress: () => {} }]}
>
Custom theme
</Banner>
)
.toJSON();

expect(tree).toMatchSnapshot();
});
255 changes: 235 additions & 20 deletions src/components/__tests__/__snapshots__/Banner.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,195 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`render visible banner, with custom theme 1`] = `
<View
style={
Object {
"backgroundColor": "#ccc",
"elevation": 1,
"shadowColor": "#000000",
"shadowOffset": Object {
"height": 0.5,
"width": 0,
},
"shadowOpacity": 0.24,
"shadowRadius": 0.75,
}
}
>
<View
style={
Array [
Object {
"alignSelf": "center",
"maxWidth": 960,
"overflow": "hidden",
"width": "100%",
},
undefined,
]
}
>
<View
style={
Object {
"height": 0,
}
}
/>
<View
onLayout={[Function]}
style={Object {}}
>
<View
style={
Object {
"flexDirection": "row",
"justifyContent": "flex-start",
"marginBottom": 0,
"marginHorizontal": 8,
"marginTop": 16,
}
}
>
<Text
style={
Array [
Object {
"color": "#000000",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"textAlign": "left",
},
Array [
Object {
"flex": 1,
"margin": 8,
},
Object {
"color": "#00f",
},
],
]
}
>
Custom theme
</Text>
</View>
<View
style={
Object {
"flexDirection": "row",
"justifyContent": "flex-end",
"margin": 4,
}
}
>
<View
style={
Object {
"backgroundColor": "transparent",
"borderColor": "transparent",
"borderRadius": 4,
"borderStyle": "solid",
"borderWidth": 0,
"elevation": 0,
"margin": 4,
"minWidth": "auto",
}
}
>
<View
accessibilityRole="button"
accessibilityState={
Object {
"disabled": undefined,
}
}
accessible={true}
focusable={true}
onClick={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Array [
Object {
"overflow": "hidden",
},
Object {
"borderRadius": 4,
},
]
}
>
<View
style={
Array [
Object {
"alignItems": "center",
"flexDirection": "row",
"justifyContent": "center",
},
undefined,
]
}
>
<Text
numberOfLines={1}
selectable={false}
style={
Array [
Object {
"color": "#000000",
"fontFamily": "System",
"fontWeight": "400",
},
Object {
"textAlign": "left",
},
Array [
Object {
"letterSpacing": 1,
"marginHorizontal": 16,
"marginVertical": 9,
"textAlign": "center",
},
Object {
"marginHorizontal": 8,
},
Object {
"textTransform": "uppercase",
},
Object {
"color": "#043",
"fontFamily": "System",
"fontWeight": "500",
},
Object {
"fontFamily": "System",
"fontWeight": "500",
},
undefined,
],
]
}
>
first
</Text>
</View>
</View>
</View>
</View>
</View>
</View>
</View>
`;

exports[`renders hidden banner, without action buttons and without image 1`] = `
<View
style={
Expand Down Expand Up @@ -74,10 +264,15 @@ exports[`renders hidden banner, without action buttons and without image 1`] = `
Object {
"textAlign": "left",
},
Object {
"flex": 1,
"margin": 8,
},
Array [
Object {
"flex": 1,
"margin": 8,
},
Object {
"color": "#000000",
},
],
]
}
>
Expand Down Expand Up @@ -161,10 +356,15 @@ exports[`renders visible banner, with action buttons and with image 1`] = `
Object {
"textAlign": "left",
},
Object {
"flex": 1,
"margin": 8,
},
Array [
Object {
"flex": 1,
"margin": 8,
},
Object {
"color": "#000000",
},
],
]
}
>
Expand Down Expand Up @@ -346,10 +546,15 @@ exports[`renders visible banner, with action buttons and without image 1`] = `
Object {
"textAlign": "left",
},
Object {
"flex": 1,
"margin": 8,
},
Array [
Object {
"flex": 1,
"margin": 8,
},
Object {
"color": "#000000",
},
],
]
}
>
Expand Down Expand Up @@ -630,10 +835,15 @@ exports[`renders visible banner, without action buttons and with image 1`] = `
Object {
"textAlign": "left",
},
Object {
"flex": 1,
"margin": 8,
},
Array [
Object {
"flex": 1,
"margin": 8,
},
Object {
"color": "#000000",
},
],
]
}
>
Expand Down Expand Up @@ -716,10 +926,15 @@ exports[`renders visible banner, without action buttons and without image 1`] =
Object {
"textAlign": "left",
},
Object {
"flex": 1,
"margin": 8,
},
Array [
Object {
"flex": 1,
"margin": 8,
},
Object {
"color": "#000000",
},
],
]
}
>
Expand Down