Write a native element
A native element is a tag your templates use that the platform's own control draws, such as a UISwitch and an Android Switch, a map or a camera preview. Add it to a native plugin, then type it for Angular's template checker.
Write the element
An element is a LynxUI subclass that makes the platform's view:
- Attributes your template sets arrive in setters.
- Events go out with
LynxDetailEvent.
On iOS
Swift can't use Lynx's LYNX_PROP_SETTER macro. So the class lists its attributes in propSetterLookUp(), each with a setter that takes the value and requestReset:
On Android
An attribute's setter is marked @LynxProp.
Give LynxDetailEvent a map Lynx can add to, such as a HashMap. Lynx adds keys of its own, and a Kotlin mapOf() throws.
Register it and size it
Name the tag and its class in the plugin's elements, for each platform:
See Make a plugin for the rest of the entry, and the tags you can't use.
An element is laid out like a <view>. Give it a size with CSS. It doesn't measure itself from its view.
Type the element
The runtime draws a tag it doesn't know as a <view>. So tell it the tag is a native element with registerNativeElement().
Then type it:
- A directive gives the template checker its attributes.
HTMLElementTagNameMapgives it its events.
Import the directive where you use the element. ng test then checks the binding's type and types $event:
Keep the screens that use it to the apps you build. Lynx Explorer and the web preview don't have your element. See Elsewhere, your plugin isn't there.
Show its children somewhere else
An element can show the Angular elements inside it in a view of the platform's own, outside the page. For example, a system sheet, a popover or a dialog.
Lynx sends a touch to the elements it finds from the page's root view. So children whose views you move out draw, but never get a tap.
To keep them interactive, subclass HostElementUI instead of LynxUI. See Show an element's children in a sheet.
Related
- Add native code: make a plugin, build and run it
- Write a native module
registerNativeElement()- The Native Plugin example
- Lynx's Custom Native Element guide
