feat(Parser): Implement utility class to parse rendererContext

This field is found in most of the newer view model nodes. It can contain accessibility labels, text, commands or nothing but logging info.
This commit is contained in:
Luan
2024-12-31 06:04:53 -03:00
parent a602a317aa
commit 3a11b99429
2 changed files with 33 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
import type { RawNode } from '../../types/index.js';
import NavigationEndpoint from '../NavigationEndpoint.js';
export type CommandContext = {
on_tap?: NavigationEndpoint;
};
export type AccessibilityContext = {
label?: string;
};
export default class RendererContext {
public command_context: CommandContext;
public accessibility_context: AccessibilityContext;
constructor(data: RawNode) {
this.command_context = {};
this.accessibility_context = {};
if (Reflect.has(data, 'commandContext')) {
if (Reflect.has(data.commandContext, 'onTap')) {
this.command_context.on_tap = new NavigationEndpoint(data.commandContext.onTap);
}
}
if (Reflect.has(data, 'accessibilityContext')) {
if (Reflect.has(data.accessibilityContext, 'label')) {
this.accessibility_context.label = data.accessibilityContext.label;
}
}
}
}