Call element methods
Some element features have no attribute: you scroll a <scroll-view> to a position, or play a <video>, by calling a method on the element. These are UI methods, functions a native element exposes that you call by name (see Glossary).
Call a method from an event handler
viewChild(…, { read: ElementRef })gives you the element.nativeElement.invoke(method, params)calls a UI method on it.- It's fire-and-forget.
invoke()returns nothing, and a failed call isn't reported. - The
?.matters outside handlers. Your app's background thread copy has no native elements, so itsnativeElementhas noinvoke. Handlers run only on the main thread, but?.keeps the same call safe in a constructor orngOnInit, which run on both.
Each element's methods and their parameters are on its API page, such as <video>. Lynx's element reference lists more, such as <scroll-view>'s scrollTo and autoScroll.
Get a method's result
To read a result, such as an element's size and position, call invoke() in a main-thread script. There it returns a Promise:
boundingClientRectreturns the element's size and position.leftandtopare measured from the top-left corner of the LynxView that shows your app.- The Promise rejects if the method fails.
console.logoutput shows in Lynx DevTool (see Debugging).
Select an element with lynx.createSelectorQuery()
Lynx's own API finds an element by selector and calls a method on it, and Lynx's documentation uses it for every UI method. It exists only on the background thread. Template handlers run on the main thread, where calling it throws lynx.createSelectorQuery is not a function.
So wrap the query in a backgroundFn(), and call it from a handler with runOnBackground():
#playermatches the element'sid, as in<video id="player">. A class (.name) or a tag name (video) also works.exec()sends the query. Nothing runs until you call it.successreceives the method's result. It runs later, so the result can't come back throughrunOnBackground(). To use a result, callinvoke()in a main-thread script, as shown above.failreceives{ code, data }. Without afailcallback, a failed call shows an error screen.
LynxAccessibility.requestFocus() calls the requestAccessibilityFocus method through createSelectorQuery(), so the same thread rule applies to it.
