pub struct SemanticsRequester { /* private fields */ }Expand description
A handle an app holds to say that what its semantics recorder would report has changed.
A .semantics() recorder is re-run on every collection, so it always reports
the app’s current answer. It cannot say when that answer changed, and a
tree is only re-collected when some node marks its semantics dirty — which
until now meant attaching a node, rebuilding its modifier chain, or a layout
pass. A screen that is one Canvas does none of those: its layout never
changes and its frame loop draws rather than recomposes, so the tree it
published at boot was the tree a screen reader kept reading.
This is the way out, and it is Jetpack Compose’s:
SemanticsModifierNode.invalidateSemantics(). Remember one requester, hang
it on the same node as the recorder, and call invalidate when the content
changes — no recomposition, no layout pass.
let semantics = remember(SemanticsRequester::new).with(Clone::clone);
// ... in the composition:
Modifier::empty()
.semantics_requester(&semantics)
.semantics(move |config| { /* reads live app state */ })
// ... and in the frame loop, guarded by a revision so an unchanged tree is
// not republished every frame:
if revision != last_revision {
last_revision = revision;
semantics.invalidate();
}Implementations§
Source§impl SemanticsRequester
impl SemanticsRequester
pub fn new() -> Self
Sourcepub fn invalidate(&self)
pub fn invalidate(&self)
Marks the attached node’s semantics for re-collection on the next frame.
Idempotent within a frame and cheap: the node joins a set the shell drains once per frame. Before the node attaches, and after it detaches, this does nothing — there is no tree to mark.
Trait Implementations§
Source§impl Clone for SemanticsRequester
impl Clone for SemanticsRequester
Source§fn clone(&self) -> SemanticsRequester
fn clone(&self) -> SemanticsRequester
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more