Skip to content

Commit

Permalink
Fix intermittent failures to measure tiled components on Android.
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswilddev committed Jul 29, 2024
1 parent 381c5e1 commit 0471621
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
2 changes: 2 additions & 0 deletions react-native/components/createTiledComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const createTiledComponent = (
if (sizing === null) {
return (
<View
collapsable={false}
ref={ref}
onLayout={onLayout}
style={globalStyles.outerView}
Expand Down Expand Up @@ -103,6 +104,7 @@ export const createTiledComponent = (

return (
<View
collapsable={false}
ref={ref}
onLayout={onLayout}
style={globalStyles.outerView}
Expand Down
22 changes: 22 additions & 0 deletions react-native/components/createTiledComponent/unit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ test('renders as expected without any children', async () => {
rendered: expect.objectContaining({
type: View,
props: {
collapsable: false,
onLayout: expect.any(Function),
style: { width: '100%', flexDirection: 'row', flexWrap: 'wrap' },
pointerEvents: 'box-none'
Expand Down Expand Up @@ -42,6 +43,7 @@ test('renders as expected without any children', async () => {
rendered: expect.objectContaining({
type: View,
props: {
collapsable: false,
onLayout: expect.any(Function),
style: { width: '100%', flexDirection: 'row', flexWrap: 'wrap' },
pointerEvents: 'box-none',
Expand All @@ -67,6 +69,7 @@ test('renders as expected with less than one row', async () => {
rendered: expect.objectContaining({
type: View,
props: {
collapsable: false,
onLayout: expect.any(Function),
style: { width: '100%', flexDirection: 'row', flexWrap: 'wrap' },
pointerEvents: 'box-none'
Expand Down Expand Up @@ -97,6 +100,7 @@ test('renders as expected with less than one row', async () => {
rendered: expect.objectContaining({
type: View,
props: {
collapsable: false,
onLayout: expect.any(Function),
style: { width: '100%', flexDirection: 'row', flexWrap: 'wrap' },
pointerEvents: 'box-none',
Expand Down Expand Up @@ -159,6 +163,7 @@ test('renders as expected with exactly one row', async () => {
rendered: expect.objectContaining({
type: View,
props: {
collapsable: false,
onLayout: expect.any(Function),
style: { width: '100%', flexDirection: 'row', flexWrap: 'wrap' },
pointerEvents: 'box-none'
Expand Down Expand Up @@ -189,6 +194,7 @@ test('renders as expected with exactly one row', async () => {
rendered: expect.objectContaining({
type: View,
props: {
collapsable: false,
onLayout: expect.any(Function),
style: { width: '100%', flexDirection: 'row', flexWrap: 'wrap' },
pointerEvents: 'box-none',
Expand Down Expand Up @@ -271,6 +277,7 @@ test('renders as expected with less than two rows', async () => {
rendered: expect.objectContaining({
type: View,
props: {
collapsable: false,
onLayout: expect.any(Function),
style: { width: '100%', flexDirection: 'row', flexWrap: 'wrap' },
pointerEvents: 'box-none'
Expand Down Expand Up @@ -301,6 +308,7 @@ test('renders as expected with less than two rows', async () => {
rendered: expect.objectContaining({
type: View,
props: {
collapsable: false,
onLayout: expect.any(Function),
style: { width: '100%', flexDirection: 'row', flexWrap: 'wrap' },
pointerEvents: 'box-none',
Expand Down Expand Up @@ -421,6 +429,7 @@ test('renders as expected with exactly two rows', async () => {
rendered: expect.objectContaining({
type: View,
props: {
collapsable: false,
onLayout: expect.any(Function),
style: { width: '100%', flexDirection: 'row', flexWrap: 'wrap' },
pointerEvents: 'box-none'
Expand Down Expand Up @@ -451,6 +460,7 @@ test('renders as expected with exactly two rows', async () => {
rendered: expect.objectContaining({
type: View,
props: {
collapsable: false,
onLayout: expect.any(Function),
style: { width: '100%', flexDirection: 'row', flexWrap: 'wrap' },
pointerEvents: 'box-none',
Expand Down Expand Up @@ -592,6 +602,7 @@ test('renders as expected with less than three rows', async () => {
rendered: expect.objectContaining({
type: View,
props: {
collapsable: false,
onLayout: expect.any(Function),
style: { width: '100%', flexDirection: 'row', flexWrap: 'wrap' },
pointerEvents: 'box-none'
Expand Down Expand Up @@ -622,6 +633,7 @@ test('renders as expected with less than three rows', async () => {
rendered: expect.objectContaining({
type: View,
props: {
collapsable: false,
onLayout: expect.any(Function),
style: { width: '100%', flexDirection: 'row', flexWrap: 'wrap' },
pointerEvents: 'box-none',
Expand Down Expand Up @@ -801,6 +813,7 @@ test('renders as expected with exactly three rows', async () => {
rendered: expect.objectContaining({
type: View,
props: {
collapsable: false,
onLayout: expect.any(Function),
style: { width: '100%', flexDirection: 'row', flexWrap: 'wrap' },
pointerEvents: 'box-none'
Expand Down Expand Up @@ -831,6 +844,7 @@ test('renders as expected with exactly three rows', async () => {
rendered: expect.objectContaining({
type: View,
props: {
collapsable: false,
onLayout: expect.any(Function),
style: { width: '100%', flexDirection: 'row', flexWrap: 'wrap' },
pointerEvents: 'box-none',
Expand Down Expand Up @@ -1029,6 +1043,7 @@ test('renders as expected without column spacing', async () => {
rendered: expect.objectContaining({
type: View,
props: {
collapsable: false,
onLayout: expect.any(Function),
style: { width: '100%', flexDirection: 'row', flexWrap: 'wrap' },
pointerEvents: 'box-none'
Expand Down Expand Up @@ -1059,6 +1074,7 @@ test('renders as expected without column spacing', async () => {
rendered: expect.objectContaining({
type: View,
props: {
collapsable: false,
onLayout: expect.any(Function),
style: { width: '100%', flexDirection: 'row', flexWrap: 'wrap' },
pointerEvents: 'box-none',
Expand Down Expand Up @@ -1251,6 +1267,7 @@ test('renders as expected without row spacing', async () => {
rendered: expect.objectContaining({
type: View,
props: {
collapsable: false,
onLayout: expect.any(Function),
style: { width: '100%', flexDirection: 'row', flexWrap: 'wrap' },
pointerEvents: 'box-none'
Expand Down Expand Up @@ -1281,6 +1298,7 @@ test('renders as expected without row spacing', async () => {
rendered: expect.objectContaining({
type: View,
props: {
collapsable: false,
onLayout: expect.any(Function),
style: { width: '100%', flexDirection: 'row', flexWrap: 'wrap' },
pointerEvents: 'box-none',
Expand Down Expand Up @@ -1473,6 +1491,7 @@ test('renders as expected without an aspect ratio or row spacing', async () => {
rendered: expect.objectContaining({
type: View,
props: {
collapsable: false,
onLayout: expect.any(Function),
style: { width: '100%', flexDirection: 'row', flexWrap: 'wrap' },
pointerEvents: 'box-none'
Expand Down Expand Up @@ -1503,6 +1522,7 @@ test('renders as expected without an aspect ratio or row spacing', async () => {
rendered: expect.objectContaining({
type: View,
props: {
collapsable: false,
onLayout: expect.any(Function),
style: { width: '100%', flexDirection: 'row', flexWrap: 'wrap' },
pointerEvents: 'box-none',
Expand Down Expand Up @@ -1686,6 +1706,7 @@ test('renders as expected without an aspect ratio', async () => {
rendered: expect.objectContaining({
type: View,
props: {
collapsable: false,
onLayout: expect.any(Function),
style: { width: '100%', flexDirection: 'row', flexWrap: 'wrap' },
pointerEvents: 'box-none'
Expand Down Expand Up @@ -1716,6 +1737,7 @@ test('renders as expected without an aspect ratio', async () => {
rendered: expect.objectContaining({
type: View,
props: {
collapsable: false,
onLayout: expect.any(Function),
style: { width: '100%', flexDirection: 'row', flexWrap: 'wrap' },
pointerEvents: 'box-none',
Expand Down
3 changes: 2 additions & 1 deletion react-native/hooks/useMeasure/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import type {

/**
* A React hook which executes a callback when an element's dimensions are first
* known or change.
* known or change. You MUST set collapsable to false on the associated view
* for this to work reliably on Android.
* @param onMeasure The callback executed when the element's dimensions are
* first known or change.
* @returns A "ref" callback and "onLayout" callback to pass to the
Expand Down
5 changes: 4 additions & 1 deletion react-native/hooks/useMeasure/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
A React hook which executes a callback when an element's dimensions are first
known or change.

You MUST set collapsable to false on the associated view for this to work
reliably on Android.

## Usage

```tsx
Expand All @@ -14,7 +17,7 @@ const ExampleScreen = () => {
});

return (
<Button ref={ref} onLayout={onLayout} />
<View collapsable={false} ref={ref} onLayout={onLayout} />
);
};
```

0 comments on commit 0471621

Please sign in to comment.