Skip to content

SquircleView renders with wrong dimensions inside flex containers #25

Description

@sherucon

Environment: react-native-figma-squircle@0.4.0, React Native (New Architecture)

When multiple SquircleView components are placed in a flexDirection: "row" container with flex: 1, the squircle background can render at incorrect dimensions — often appearing visually squashed or mismatched compared to sibling views.

Reproduction:

<View style={{ flexDirection: "row", gap: 8 }}>
  <Pressable style={{ flex: 1, height: 44 }}>
    <SquircleView
      style={StyleSheet.absoluteFill}
      squircleParams={{ cornerSmoothing: 1, cornerRadius: 22, fillColor: "blue" }}
    />
    <Text>Subscribe</Text>
  </Pressable>
  <Pressable style={{ flex: 1, height: 44 }}>
    <SquircleView
      style={StyleSheet.absoluteFill}
      squircleParams={{ cornerSmoothing: 1, cornerRadius: 22, fillColor: "transparent", strokeColor: "gray", strokeWidth: 1 }}
    />
    <Text>Message</Text>
  </Pressable>
</View>

Expected: Both buttons render identically-sized squircle backgrounds.
Actual: The first button's squircle renders at wrong dimensions (often appearing squashed), while the second renders correctly — or vice versa. The behavior is inconsistent across mounts.

Root cause: The internal Rect component (src/index.tsx L143–165) uses useLayoutEffect with an empty dependency array [] and measureInWindow to capture dimensions:

useLayoutEffect(() => {
  ref.current?.measureInWindow((_x, _y, width, height) => {
    setRect({ width, height })
  })
}, [])  // ← never re-runs

This has two problems:

  1. Measures once, never updates — if the view's bounds change after mount (screen rotation, flex resolution, dynamic content), the SVG path is permanently stale.
  2. Flex timing race — in flex containers, measureInWindow fires during the initial layout pass. When multiple flex siblings are resolving their widths simultaneously, the callback can capture intermediate/pre-resolution dimensions. The SVG path is then computed for a width the view no longer has.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions