Skip to content

Commit 0d34352

Browse files
committed
Fix backgrounds accepting presses.
1 parent 31c3869 commit 0d34352

File tree

4 files changed

+41
-14
lines changed

4 files changed

+41
-14
lines changed

components/createFlatColorBackgroundComponent/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,9 @@ export const createFlatColorBackgroundComponent = (
2121
},
2222
});
2323

24-
return ({ size, children }) => <View style={styles[size]}>{children}</View>;
24+
return ({ size, children }) => (
25+
<View style={styles[size]} pointerEvents="box-none">
26+
{children}
27+
</View>
28+
);
2529
};

components/createFlatColorBackgroundComponent/unit.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test(`renders as expected when fitting the content`, () => {
1313
);
1414

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

3131
expect(unwrapRenderedFunctionComponent(rendered)).toEqual(
32-
<View style={{ backgroundColor: `red`, flexGrow: 1 }}>
32+
<View
33+
style={{ backgroundColor: `red`, flexGrow: 1 }}
34+
pointerEvents="box-none"
35+
>
3336
<Text>Test Content</Text>
3437
</View>
3538
);

components/createImageBackgroundComponent/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { Image, ImageSourcePropType, StyleSheet, View } from "react-native";
33

44
const styles = StyleSheet.create({
55
image: {
6+
width: `100%`,
7+
height: `100%`,
8+
},
9+
imageWrapper: {
610
position: `absolute`,
711
left: 0,
812
top: 0,
@@ -29,8 +33,11 @@ export const createImageBackgroundComponent = (
2933
{...(size === `fillsContainer`
3034
? { style: styles.containerFillingView }
3135
: {})}
36+
pointerEvents="box-none"
3237
>
33-
<Image source={source} style={styles.image} resizeMode="cover" />
38+
<View style={styles.imageWrapper} pointerEvents="none">
39+
<Image source={source} style={styles.image} resizeMode="cover" />
40+
</View>
3441
{children}
3542
</View>
3643
);

components/createImageBackgroundComponent/unit.tsx

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,23 @@ test(`renders as expected when fitting the content`, () => {
1313
);
1414

1515
expect(unwrapRenderedFunctionComponent(rendered)).toEqual(
16-
<View>
17-
<Image
18-
source={{ uri: `Example Uri` }}
16+
<View pointerEvents="box-none">
17+
<View
18+
pointerEvents="none"
1919
style={{
2020
position: `absolute`,
2121
left: 0,
2222
top: 0,
2323
width: `100%`,
2424
height: `100%`,
2525
}}
26-
resizeMode="cover"
27-
/>
26+
>
27+
<Image
28+
source={{ uri: `Example Uri` }}
29+
style={{ width: `100%`, height: `100%` }}
30+
resizeMode="cover"
31+
/>
32+
</View>
2833
<Text>Test Content</Text>
2934
</View>
3035
);
@@ -40,18 +45,26 @@ test(`renders as expected when filling the container`, () => {
4045
);
4146

4247
expect(unwrapRenderedFunctionComponent(rendered)).toEqual(
43-
<View style={{ flexGrow: 1 }}>
44-
<Image
45-
source={{ uri: `Example Uri` }}
48+
<View style={{ flexGrow: 1 }} pointerEvents="box-none">
49+
<View
4650
style={{
4751
position: `absolute`,
4852
left: 0,
4953
top: 0,
5054
width: `100%`,
5155
height: `100%`,
5256
}}
53-
resizeMode="cover"
54-
/>
57+
pointerEvents="none"
58+
>
59+
<Image
60+
source={{ uri: `Example Uri` }}
61+
style={{
62+
width: `100%`,
63+
height: `100%`,
64+
}}
65+
resizeMode="cover"
66+
/>
67+
</View>
5568
<Text>Test Content</Text>
5669
</View>
5770
);

0 commit comments

Comments
 (0)