feat(react-native): support custom directives - #314
Open
karankalsi wants to merge 4 commits into
Open
Conversation
Contributor
|
@karankalsi is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
directivesprop to React Native'sJSONUIProviderWhy
@json-render/reactsupports custom directives, but@json-render/react-nativecannot currently pass a directive registry intoresolveElementProps. This brings the React Native renderer to parity so custom$-prefixed dynamic values can compose with built-in expressions such as$state.Testing
pnpm type-check— 59/59 workspace tasks passed on Node 24.12.0 and pnpm 11.1.3pnpm exec prettier --check packages/react-native/src/renderer.tsx$uppercasedirective wrapping$staterendereddirectives are workingasDIRECTIVES ARE WORKINGComposed directive example
This parity example registers both directives with
defineDirective. Each resolver callsresolvePropValue, so$formatcan consume the result of$math, while$mathresolves its operands from$state:Mock spec:
{ "root": "directive-test", "state": { "price": 12.5, "qty": 2 }, "elements": { "directive-test": { "type": "Text", "props": { "text": { "$format": "currency", "value": { "$math": "multiply", "a": { "$state": "/price" }, "b": { "$state": "/qty" } }, "currency": "USD" } }, "children": [] } } }With
price: 12.5andqty: 2, the resolved text is$25.00.Functions and directives parity
React Native now matches
@json-render/reactfor both entry points:JSONUIProvideracceptsfunctionsanddirectives.Components returned by
createRendereracceptfunctionsanddirectives.Both paths provide
FunctionsContextand a memoizedDirectivesContextregistry to element prop resolution, including repeat scopes.Programmatically verified the composed mock resolves to
$25.00withprice: 12.5andqty: 2.