@blario/react-native 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/fiber/text.ts CHANGED
@@ -3,6 +3,8 @@ import type { Fiber } from './types.ts';
3
3
 
4
4
  const PRIVATE_USE_GLYPHS = /[-\u{F0000}-\u{10FFFF}]/gu;
5
5
 
6
+ export const TEXT_HOST_TYPE = 'RCTText';
7
+
6
8
  export function normalizeText(value: string): string {
7
9
  return value.replace(PRIVATE_USE_GLYPHS, '').replace(/\s+/g, ' ').trim();
8
10
  }
@@ -124,6 +124,7 @@ export class SnapshotCapturer {
124
124
  rect,
125
125
  scroll: candidate.kind === 'scroll' ? describeScrollDirections(geometries.get(candidate.fiber) ?? null) : null,
126
126
  offscreen,
127
+ wheelOption: candidate.wheelOption,
127
128
  }),
128
129
  );
129
130
  if (mode === 'register') {
@@ -1,5 +1,5 @@
1
1
  import { childrenOf, componentName, firstHostDescendant, isHostComponent, propsOf } from '../fiber/reader.ts';
2
- import { collectText } from '../fiber/text.ts';
2
+ import { collectText, TEXT_HOST_TYPE } from '../fiber/text.ts';
3
3
  import type { Fiber } from '../fiber/types.ts';
4
4
  import { classify } from './classify.ts';
5
5
  import type { ElementKind } from './kinds.ts';
@@ -19,7 +19,6 @@ export interface Candidate {
19
19
  }
20
20
 
21
21
  const MODAL_COMPONENT_NAME = 'Modal';
22
- const TEXT_HOST_TYPE = 'RCTText';
23
22
  const WHEEL_OPTION_LIMIT = 24;
24
23
  const TEXT_BLOCK_LIMIT = 800;
25
24
  const HEADING_ROLES: readonly string[] = ['header', 'heading'];
@@ -51,6 +51,7 @@ function renderButton(view: ElementView, twins: number): string {
51
51
  const tag = openTag('button', [
52
52
  ['role', view.role],
53
53
  ['testID', view.testID],
54
+ ['list', view.list],
54
55
  ['icon', view.icon],
55
56
  ['offscreen', view.offscreen],
56
57
  ...commonStateAttributes(view),
@@ -94,6 +95,7 @@ function renderSwitch(view: ElementView, twins: number): string {
94
95
  function renderScroll(view: ElementView): string {
95
96
  const tag = openTag('scroll', [
96
97
  ['testID', view.testID],
98
+ ['list', view.list],
97
99
  ['scroll', view.scroll],
98
100
  ]);
99
101
  return `${tag} />`;
@@ -113,7 +115,7 @@ function renderBody(view: ElementView, twins: number): string {
113
115
  }
114
116
 
115
117
  export function twinSignature(view: ElementView): string {
116
- return [view.kind, view.label, view.icon ?? '', view.role ?? ''].join('|');
118
+ return [view.kind, view.label, view.icon ?? '', view.role ?? '', view.list ?? ''].join('|');
117
119
  }
118
120
 
119
121
  export function countTwins(views: ElementView[]): Map<string, number> {
@@ -2,6 +2,7 @@ import { collectText, precedingText } from '../fiber/text.ts';
2
2
  import { propsOf } from '../fiber/reader.ts';
3
3
  import type { Fiber } from '../fiber/types.ts';
4
4
  import type { Rect } from '../host/rect.ts';
5
+ import { scrollInstanceOf } from './classify.ts';
5
6
  import { iconNameIn } from './icon.ts';
6
7
  import type { Offscreen } from './visibility.ts';
7
8
  import type { ElementKind } from './kinds.ts';
@@ -33,9 +34,24 @@ export interface ElementView {
33
34
  selected: boolean | null;
34
35
  scroll: string | null;
35
36
  offscreen: Offscreen | null;
37
+ list: string | null;
36
38
  rect: Rect;
37
39
  }
38
40
 
41
+ const LIST_NAME_DEPTH = 8;
42
+
43
+ // What a list is called: hosts name the view around it, as AgendaPro does with Hours and Minutes.
44
+ export function listNameOf(list: Fiber, ancestors: Fiber[]): string | null {
45
+ for (const fiber of [list, ...ancestors.slice(-LIST_NAME_DEPTH).reverse()]) {
46
+ const props = propsOf(fiber);
47
+ const name = explicitLabelOf(props) ?? testIdOf(props);
48
+ if (name !== null) {
49
+ return name;
50
+ }
51
+ }
52
+ return null;
53
+ }
54
+
39
55
  function labelFor(kind: ElementKind, fiber: Fiber, ancestors: Fiber[]): string {
40
56
  const explicit = explicitLabelOf(propsOf(fiber));
41
57
  if (explicit !== null) {
@@ -57,6 +73,23 @@ export interface ViewSource {
57
73
  rect: Rect;
58
74
  scroll: string | null;
59
75
  offscreen?: Offscreen | null;
76
+ wheelOption?: boolean;
77
+ }
78
+
79
+ function listOfView({ kind, fiber, ancestors, wheelOption }: ViewSource): string | null {
80
+ if (kind === 'scroll') {
81
+ return listNameOf(fiber, ancestors);
82
+ }
83
+ if (wheelOption !== true) {
84
+ return null;
85
+ }
86
+ for (let index = ancestors.length - 1; index >= 0; index -= 1) {
87
+ const ancestor = ancestors[index];
88
+ if (ancestor !== undefined && scrollInstanceOf(ancestor) !== null) {
89
+ return listNameOf(ancestor, ancestors.slice(0, index));
90
+ }
91
+ }
92
+ return null;
60
93
  }
61
94
 
62
95
  export function buildView(source: ViewSource): ElementView {
@@ -82,6 +115,7 @@ export function buildView(source: ViewSource): ElementView {
82
115
  selected: flags.selected,
83
116
  scroll,
84
117
  offscreen,
118
+ list: listOfView(source),
85
119
  rect,
86
120
  };
87
121
  }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const SDK_VERSION = '0.1.4';
1
+ export const SDK_VERSION = '0.1.5';