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

fix: correct changing Dialog backdrop color #3259

Merged
merged 1 commit into from
Jul 17, 2022
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
1 change: 1 addition & 0 deletions src/components/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const Dialog = ({
styles.container,
style,
]}
theme={theme}
>
{React.Children.toArray(children)
.filter((child) => child != null && typeof child !== 'boolean')
Expand Down
7 changes: 6 additions & 1 deletion src/components/FAB/FABGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ type Props = {
* Custom color for the `FAB`.
*/
color?: string;
/**
* Custom backdrop color for opened speed dial background.
*/
backdropColor?: string;
/**
* Function to execute on pressing the `FAB`.
*/
Expand Down Expand Up @@ -163,6 +167,7 @@ const FABGroup = ({
testID,
onStateChange,
color: colorProp,
backdropColor,
}: Props) => {
const { current: backdrop } = React.useRef<Animated.Value>(
new Animated.Value(0)
Expand Down Expand Up @@ -267,7 +272,7 @@ const FABGroup = ({
styles.backdrop,
{
opacity: backdropOpacity,
backgroundColor: colors.backdrop,
backgroundColor: backdropColor || colors.backdrop,
},
]}
/>
Expand Down
17 changes: 14 additions & 3 deletions src/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
getBottomSpace,
} from 'react-native-iphone-x-helper';
import Surface from './Surface';
import { useTheme } from '../core/theming';
import { withTheme } from '../core/theming';
import useAnimatedValue from '../utils/useAnimatedValue';
import { addEventListener } from '../utils/addEventListener';

Expand Down Expand Up @@ -49,6 +49,11 @@ type Props = {
* Use this prop to change the default wrapper style or to override safe area insets with marginTop and marginBottom.
*/
style?: StyleProp<ViewStyle>;
/**
* @optional
*/
theme: ReactNativePaper.Theme;
testID?: string;
};

const DEFAULT_DURATION = 220;
Expand Down Expand Up @@ -94,22 +99,24 @@ const BOTTOM_INSET = getBottomSpace();
* export default MyComponent;
* ```
*/
export default function Modal({
function Modal({
dismissable = true,
visible = false,
overlayAccessibilityLabel = 'Close modal',
onDismiss,
children,
contentContainerStyle,
style,
theme,
testID,
}: Props) {
const visibleRef = React.useRef(visible);

React.useEffect(() => {
visibleRef.current = visible;
});

const { colors, animation } = useTheme();
const { colors, animation } = theme;

const opacity = useAnimatedValue(visible ? 1 : 0);

Expand Down Expand Up @@ -208,6 +215,7 @@ export default function Modal({
accessibilityLiveRegion="polite"
style={StyleSheet.absoluteFill}
onAccessibilityEscape={hideModal}
testID={testID}
>
<TouchableWithoutFeedback
accessibilityLabel={overlayAccessibilityLabel}
Expand All @@ -217,6 +225,7 @@ export default function Modal({
importantForAccessibility="no"
>
<Animated.View
testID={`${testID}-backdrop`}
style={[
styles.backdrop,
{ backgroundColor: colors.backdrop, opacity },
Expand Down Expand Up @@ -247,6 +256,8 @@ export default function Modal({
);
}

export default withTheme(Modal);

const styles = StyleSheet.create({
backdrop: {
flex: 1,
Expand Down
25 changes: 25 additions & 0 deletions src/components/__tests__/Modal.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as React from 'react';
import { render } from 'react-native-testing-library';
import Modal from '../Modal';

describe('Modal', () => {
it('should render custom backdrop color', () => {
const { getByTestId } = render(
<Modal
visible={true}
testID="modal"
theme={{
colors: {
backdrop: 'transparent',
},
}}
/>
);

expect(getByTestId('modal-backdrop').props.style).toEqual(
expect.arrayContaining([
expect.objectContaining({ backgroundColor: 'transparent' }),
])
);
});
});