-
Notifications
You must be signed in to change notification settings - Fork 27
fix: prevent Rokt layout views from collapsing to zero height #368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /** | ||
| * `RoktLayoutView` sizes its native view from the height the Rokt SDK measures and | ||
| * pushes back to JS. If the style also sets `flex: 1`, that expands to | ||
| * `flexBasis: 0%`, which takes precedence over `height` on the parent's main axis — | ||
| * so inside any auto-height column parent the layout collapses to 0 and the | ||
| * placement is never visible, even though it selected successfully and reported a | ||
| * height. Guard both platform implementations against that regression. | ||
| */ | ||
| const mockAddListener = jest.fn(() => ({ remove: jest.fn() })); | ||
|
|
||
| // `react` and `react-native` are peer dependencies and are not installed here, so | ||
| // stub the pieces these components touch. `createElement` just records what the | ||
| // component asked for, which is all the assertions below need. | ||
| jest.mock( | ||
| 'react', | ||
| () => { | ||
| class Component<P, S> { | ||
| props: P; | ||
| state!: S; | ||
| constructor(props: P) { | ||
| this.props = props; | ||
| } | ||
| setState(partial: Partial<S>) { | ||
| this.state = { ...this.state, ...partial }; | ||
| } | ||
| } | ||
| const createElement = ( | ||
| type: unknown, | ||
| props: Record<string, unknown> | null | ||
| ) => ({ type, props: props ?? {} }); | ||
| return { __esModule: true, default: { createElement }, Component }; | ||
| }, | ||
| { virtual: true } | ||
| ); | ||
|
|
||
| jest.mock( | ||
| 'react-native', | ||
| () => ({ | ||
| // Pass styles through unchanged so the test can read the resolved values. | ||
| StyleSheet: { create: (styles: unknown) => styles }, | ||
| NativeModules: { RoktEventManager: {} }, | ||
| NativeEventEmitter: jest.fn(() => ({ addListener: mockAddListener })), | ||
| requireNativeComponent: jest.fn(() => 'RoktLegacyLayout'), | ||
| TurboModuleRegistry: { getEnforcing: jest.fn(() => ({})) }, | ||
| }), | ||
| { virtual: true } | ||
| ); | ||
|
|
||
| jest.mock( | ||
| '../codegenSpecs/rokt/RoktLayoutNativeComponent', | ||
| () => ({ __esModule: true, default: 'RoktNativeLayout' }), | ||
| { virtual: true } | ||
| ); | ||
|
|
||
| import { RoktLayoutView as IosLayoutView } from '../rokt/rokt-layout-view.ios'; | ||
| import { RoktLayoutView as AndroidLayoutView } from '../rokt/rokt-layout-view.android'; | ||
|
|
||
| type LayoutViewCtor = typeof IosLayoutView | typeof AndroidLayoutView; | ||
|
|
||
| /** Renders the component and flattens the style array it hands the native view. */ | ||
| function resolvedStyle(Ctor: LayoutViewCtor, height: number) { | ||
| const instance = new Ctor({ placeholderName: 'Location1' }); | ||
| // The measured height normally arrives via a native event; set it directly so the | ||
| // test does not depend on the platform-specific event plumbing. | ||
| instance.state = { ...instance.state, height }; | ||
| const element = instance.render() as React.ReactElement<{ style: object[] }>; | ||
| return Object.assign({}, ...element.props.style) as Record<string, unknown>; | ||
| } | ||
|
|
||
| describe.each([ | ||
| ['ios', IosLayoutView], | ||
| ['android', AndroidLayoutView], | ||
| ])('RoktLayoutView (%s) style', (_platform, Ctor) => { | ||
| it('applies the measured height', () => { | ||
| expect(resolvedStyle(Ctor, 530)).toMatchObject({ height: 530 }); | ||
| }); | ||
|
|
||
| it('does not set flex, which would override the height and collapse the view', () => { | ||
| const style = resolvedStyle(Ctor, 530); | ||
| expect(style.flex).toBeUndefined(); | ||
| expect(style.flexBasis).toBeUndefined(); | ||
| expect(style.flexGrow).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('stretches to the full available width', () => { | ||
| expect(resolvedStyle(Ctor, 530)).toMatchObject({ alignSelf: 'stretch' }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.