Embedding LynxView into Native View
LynxView itself is a native view that can easily be used as a full-screen view, or be embedded within a non-full-screen native view.
LynxView corresponds to the Page element. It only allows the client to set size constraints on LynxView, and you generally cannot directly modify the Page's style to set its size.
The client sets different size constraints on LynxView, which translates to setting size constraints on the Page. The Lynx layout engine uses these constraints to calculate the size of the Page node and all its child nodes.
Constrain the size of LynxView
Constraint mode
You should proactively set its size constraints, when creating a LynxView on iOS.
There are two ways to set size constraints for LynxView.
- Using
updateViewportWithPreferredLayoutWidthandsetLayoutWidthMode、setLayoutHeightModeto set fixed or flexible sizes. - Using
lynxviewbuilder#frameto set fixed size.
Supported constraint modes:
-
LynxViewSizeModeUndefinedLynxView's size is determined by Page content, with no parent constraints.
-
LynxViewSizeModeExactLynxView's size is fixed, same as the Page element's size.
-
LynxViewSizeModeMaxLynxView's maximum width or height.
LynxView with fixed size
Use the LynxViewBuilder#frame
You can set the frame property size when creating LynxView, so the size of LynxView is fixed.
For example, if you want to fix the size of LynxView to 400x200, you can do it as follows:
Use preferredLayoutWidth/preferredLayoutHeight and layoutWidthMode/layoutHeightMode
For example:
LynxView with flexible size
If you want LynxView to adapt its size based on its content, you can either avoid setting LynxViewBuilder#frame, or set setLayoutWidth/HeightMode to LynxViewSizeModeUndefined or LynxViewSizeModeMax.