Skip to content

fix: embedded view collapsing to zero height in a column container - #290

Merged
thomson-t merged 1 commit into
mainfrom
fix/embedded-view-zero-height-in-column-container
Jul 29, 2026
Merged

fix: embedded view collapsing to zero height in a column container#290
thomson-t merged 1 commit into
mainfrom
fix/embedded-view-zero-height-in-column-container

Conversation

@thomson-t

Copy link
Copy Markdown
Contributor

Background

  • RoktEmbeddedView styles its own native view with flex: 1 alongside the height it receives from the native SDK:

    style={[styles.widget, { height: this.state.height }]}
  • In Yoga, flex: 1 expands to flexGrow: 1, flexShrink: 1, flexBasis: 0%, and flexBasis takes precedence over height on the parent's main axis. Whenever the view is rendered inside an auto-height column container, the base size resolves to 0, flexGrow has no free space to distribute, and the view stays 0pt tall.

  • The result is a silent failure that looks like a selection or targeting problem: the placement is selected, PlacementReady and PlacementInteractive fire, the native SDK reports the measured height to JS, and nothing is ever visible — so no impression or view signal follows.

  • This is easy to miss because it depends entirely on the immediate parent. It works when the parent does not constrain the main axis, for example as a direct child of a ScrollView as in RoktSampleApp, which is the arrangement used in our sample app and docs. Wrapping the component in a plain <View> — a very common integration pattern — is enough to trigger it.

What Has Changed

  • Replaced flex: 1 with alignSelf: "stretch" in styles.widget in both rokt-embedded-view.ios.tsx and rokt-embedded-view.android.tsx.
  • alignSelf: "stretch" still gives the widget the full available width in a column layout, but leaves the main axis untouched so the measured height applies.
  • Added a comment on both platforms explaining why flex: 1 must not be reintroduced.
  • No public API change. No change to the height/margin event plumbing.

Screenshots/Video

Reproduced with a minimal app that renders <RoktEmbeddedView> inside <View style={{ marginBottom: 24 }}> (an auto-height column parent), on iOS 26.4 simulator, React Native 0.81.5, New Architecture enabled.

Before — placement selected and height reported, container never grows:

selectPlacements(...) placeholders={"RoktEmbedded1":74}
RoktEvents: PlacementReady
RoktEvents: PlacementInteractive
WidgetHeightChanges: RoktEmbedded1 height=186
WidgetHeightChanges: RoktEmbedded1 height=470.67
WidgetHeightChanges: RoktEmbedded1 height=530.33
container onLayout height=0        <-- never grows, nothing rendered

After — same app, same parent, no consumer-side change: the layout renders at its
reported height.

Checklist

  • I have performed a self-review of my own code.
  • I have made corresponding changes to the documentation.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have tested this locally.

Additional Notes

  • Tests: the package has no JS test harness (Rokt.Widget/package.json"test": "echo \"Error: no test specified\""), so there is nowhere to land a unit test for this. A layout regression test needs a renderer assertion on the resolved height, which would mean introducing jest + react-test-renderer to the package. Happy to do that as a follow-up if we want it.
  • Docs: no doc change needed — the README example does not set a wrapper style, and it now works in any container.
  • Verified on: stock flex: 1 fails and the patched style renders, on both 4.11.2 and 4.12.2, inline and inside a Modal. Behaviour as a direct ScrollView child is unchanged.
  • Android caveat unrelated to this PR: on RN 0.83+ with the New Architecture, versions before 5.0.1 never deliver the height to JS at all (fixed in fix(android): render embedded placements on New Architecture via EventDispatcher #272). This change is necessary but not sufficient on those older versions.
  • The same flex: 1 pattern exists in mParticle/react-native-mparticle (js/rokt/rokt-layout-view.{ios,android}.tsx), which ports this component as RoktLayoutView. Worth porting this fix there too.

Reference Issue (For employees only. Ignore if you are an outside contributor)

  • No ticket — found while investigating an embedded placement that selected successfully but never rendered.

`RoktEmbeddedView` styled its own native view with `flex: 1` alongside the
height it receives from the native SDK:

    style={[styles.widget, { height: this.state.height }]}

In Yoga, `flex: 1` expands to `flexGrow: 1, flexShrink: 1, flexBasis: 0%`,
and `flexBasis` takes precedence over `height` on the parent's main axis.
Whenever the view is rendered inside an auto-height column container the base
size therefore resolved to 0, `flexGrow` had no free space to distribute, and
the view stayed 0pt tall. The placement was selected, `PlacementReady` and
`PlacementInteractive` fired and the measured height reached JS, but nothing
was ever visible and no impression or view signal followed.

It only worked when the immediate parent happened not to constrain the main
axis, for example a direct child of a `ScrollView` as used in RoktSampleApp,
which is why it went unnoticed.

Replace `flex: 1` with `alignSelf: "stretch"` on both platforms. That still
gives the widget the full available width, but leaves the main axis alone so
the measured `height` applies.

Co-Authored-By: Claude <noreply@anthropic.com>
@thomson-t
thomson-t requested a review from a team as a code owner July 29, 2026 13:34
@paved-road-agent

Copy link
Copy Markdown

🛣️ ROKT Data Platform Paved Roads Scan Complete

No paved-road issues detected

Scanned files against 2 rules. · Reviewed commit: 7a2b7e57b5

📜 Scan history (1 scan)
Commit Time (UTC) Status Findings
7a2b7e5 2026-07-29 13:34:16 ✅ success 0
ℹ️ About ROKT Data Platform Paved Roads Agent

This scan was performed by the ROKT Data Platform Paved Roads Agent, an automated paved-road standards review tool for pull requests. See the User Guide for details on severity levels, feedback reactions, and scan configuration.

Reply @paved-road-agent help for the list of commands you can run on this PR.

@pr-security-agent

Copy link
Copy Markdown

🔒 Security Scan Complete

No security issues detected

Scanned files against 75 rules. · Reviewed commit: 7a2b7e57b5

📜 Scan history (1 scan)
Commit Time (UTC) Status Findings
7a2b7e5 2026-07-29 13:34:17 ✅ success 0
ℹ️ About PR Security Agent

This scan was performed by PR Security Agent, an automated security review tool for pull requests. See the User Guide for details on severity levels, feedback reactions, and scan configuration.

Reply @pr-security-agent help for the list of commands you can run on this PR.

@thomson-t
thomson-t merged commit 340d5cf into main Jul 29, 2026
10 checks passed
@thomson-t
thomson-t deleted the fix/embedded-view-zero-height-in-column-container branch July 29, 2026 14:18
@rokt-releases rokt-releases Bot mentioned this pull request Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants