Skip to content

Commit

Permalink
Fix backgrounds accepting presses.
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswilddev committed Nov 26, 2021
1 parent 31c3869 commit 0d34352
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
6 changes: 5 additions & 1 deletion components/createFlatColorBackgroundComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@ export const createFlatColorBackgroundComponent = (
},
});

return ({ size, children }) => <View style={styles[size]}>{children}</View>;
return ({ size, children }) => (
<View style={styles[size]} pointerEvents="box-none">
{children}
</View>
);
};
7 changes: 5 additions & 2 deletions components/createFlatColorBackgroundComponent/unit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test(`renders as expected when fitting the content`, () => {
);

expect(unwrapRenderedFunctionComponent(rendered)).toEqual(
<View style={{ backgroundColor: `red` }}>
<View style={{ backgroundColor: `red` }} pointerEvents="box-none">
<Text>Test Content</Text>
</View>
);
Expand All @@ -29,7 +29,10 @@ test(`renders as expected when filling the container`, () => {
);

expect(unwrapRenderedFunctionComponent(rendered)).toEqual(
<View style={{ backgroundColor: `red`, flexGrow: 1 }}>
<View
style={{ backgroundColor: `red`, flexGrow: 1 }}
pointerEvents="box-none"
>
<Text>Test Content</Text>
</View>
);
Expand Down
9 changes: 8 additions & 1 deletion components/createImageBackgroundComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { Image, ImageSourcePropType, StyleSheet, View } from "react-native";

const styles = StyleSheet.create({
image: {
width: `100%`,
height: `100%`,
},
imageWrapper: {
position: `absolute`,
left: 0,
top: 0,
Expand All @@ -29,8 +33,11 @@ export const createImageBackgroundComponent = (
{...(size === `fillsContainer`
? { style: styles.containerFillingView }
: {})}
pointerEvents="box-none"
>
<Image source={source} style={styles.image} resizeMode="cover" />
<View style={styles.imageWrapper} pointerEvents="none">
<Image source={source} style={styles.image} resizeMode="cover" />
</View>
{children}
</View>
);
Expand Down
33 changes: 23 additions & 10 deletions components/createImageBackgroundComponent/unit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,23 @@ test(`renders as expected when fitting the content`, () => {
);

expect(unwrapRenderedFunctionComponent(rendered)).toEqual(
<View>
<Image
source={{ uri: `Example Uri` }}
<View pointerEvents="box-none">
<View
pointerEvents="none"
style={{
position: `absolute`,
left: 0,
top: 0,
width: `100%`,
height: `100%`,
}}
resizeMode="cover"
/>
>
<Image
source={{ uri: `Example Uri` }}
style={{ width: `100%`, height: `100%` }}
resizeMode="cover"
/>
</View>
<Text>Test Content</Text>
</View>
);
Expand All @@ -40,18 +45,26 @@ test(`renders as expected when filling the container`, () => {
);

expect(unwrapRenderedFunctionComponent(rendered)).toEqual(
<View style={{ flexGrow: 1 }}>
<Image
source={{ uri: `Example Uri` }}
<View style={{ flexGrow: 1 }} pointerEvents="box-none">
<View
style={{
position: `absolute`,
left: 0,
top: 0,
width: `100%`,
height: `100%`,
}}
resizeMode="cover"
/>
pointerEvents="none"
>
<Image
source={{ uri: `Example Uri` }}
style={{
width: `100%`,
height: `100%`,
}}
resizeMode="cover"
/>
</View>
<Text>Test Content</Text>
</View>
);
Expand Down

0 comments on commit 0d34352

Please sign in to comment.