You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JSX runtime (part 2 of 3) - more formal rendering logic for both classic and new jsx runtimes (#3947)
* rework jsx helpers for both new and old runtimes
* implement both new and old render patterns for classic and jsx-runtimes
* Change files
* move package README.md files to be next to the source code
* update documentation
* Change files
* prettier format updates to documentation
* tweak documentation just a bit
This package provides core types and helpers used by both the old and new versions of the framework.
3
+
This package provides core implementations and types to support both the legacy and current frameworks.
4
4
5
5
Several previously standalone packages have had their implementations moved into this package. This allows them to share certain typings and helpers without having to work around circular dependency issues. The moved packages are:
The functionality in these packages can be imported either by the base entry point for the package, or by using dedicated exports. The previous packages will continue to exist for the time being but are now just references to their individual exports. Note that export maps require special handling for metro bundling (with the exception of the jsx-runtime export) so the export maps are primarily for use
12
-
in JS/web projects.
11
+
The functionality in these packages is now exposed as part of this package.
13
12
14
-
## Type Helpers
13
+
## Component Patterns
15
14
16
-
- TODO: There are a number of issues with the way types are handled in the larger fluentui-react-native project, helpers and core types will be added here to help solve inference issues, avoid hard typecasts, and help the project eventually move to typescript 5.x.
15
+
The shared patterns for rendering components, as well as the JSX handlers have been centralized in this package. More information can be found [here](./src/component-patterns/README.md).
17
16
18
-
## JSX Helpers
17
+
## Type Helpers
19
18
20
-
- TODO: Both classic and the new jsx-runtime helpers will eventually come out of this package and be shared between old and new frameworks. This will be necessary to improve typing across the board.
19
+
- TODO: There are a number of issues with the way types are handled in the larger fluentui-react-native project, helpers and core types will be added here to help solve inference issues, avoid hard typecasts, and help the project eventually move to typescript 5.x.
# `fluentui-react-native` - Common component patterns
2
+
3
+
These are the base component patterns shared across the deprecated or v0 framework (found under packages/deprecated), and the newer framework (found under packages/framework). This also includes the custom JSX handlers required to render them properly.
4
+
5
+
There are two main patterns exposed here: direct rendering and staged rendering.
6
+
7
+
## Direct Rendering
8
+
9
+
The direct rendering pattern allows a component to be called directly, rather than creating a new entry in the DOM.
10
+
11
+
As an example, if you want to create a wrapper around a component called `MyText` that has `italicize` as one of its props, that always wants to set that value to true. You could define:
When this is rendered, there is an entry for `MyNewText` which contains a `MyText` (another entry), which might contains `Text` (for react-native usage). The direct rendering pattern is one where a component can denote that it is safe to be called directly as a function, instead operating as a prop transform that gets applied to the underlying component.
20
+
21
+
- For the above to be safe, `MyNewText` should NOT use hooks. In the case of any conditional rendering logic this will break the rule of hooks.
22
+
23
+
There are two types of implementations in this folder:
24
+
25
+
-`DirectComponent` - a functional component that marks itself as direct with a `_callDirect: true` attached property. This will then be called as a normal function component, with children included as part of props.
26
+
-`LegacyDirectComponent` - the pattern currently used in this library that should be moved away from. In this case `_canCompose: true` is set as an attached property, and the function component will be called with children split from props.
27
+
28
+
The internal logic of the JSX rendering helpers will handle both patterns. In the case of the newer `DirectComponent` pattern, the component will still work, even without any jsx hooks, whereas the `LegacyDirectComponent` pattern will have a somewhat undefined behavior with regards to children.
29
+
30
+
## Staged Rendering
31
+
32
+
The issue with the direct component pattern above, is that hooks are integral to writing functional components. The staged rendering pattern is designed to help with this. In this case a component is implemented in two stages, the prep stage where hooks are called, and the rendering stage where the tree is emitted.
33
+
34
+
As above there is a newer and older version of the pattern.
35
+
36
+
-`StagedComponent` - the newer version of the pattern, where the returned component function expects children as part of props.
37
+
-`StagedRender` - the older version, where children are split out and JSX hooks are required to render correctly.
38
+
39
+
Note that while the newer patterns work without any JSX hooks, the hooks will enable the element flattening.
0 commit comments