Skip to content

Commit

Permalink
Merge pull request #123 from NoriginMedia/api-cleanup
Browse files Browse the repository at this point in the history
Remove startDrawLayouts and onKeyEvent from public API
  • Loading branch information
xavi160 authored Mar 19, 2024
2 parents 60e2de1 + 7ad6d44 commit 3306b4c
Showing 1 changed file with 24 additions and 38 deletions.
62 changes: 24 additions & 38 deletions src/SpatialNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,6 @@ class SpatialNavigationService {
this.keyUpEventListener = null;
this.keyMap = DEFAULT_KEY_MAP;

this.onKeyEvent = this.onKeyEvent.bind(this);
this.pause = this.pause.bind(this);
this.resume = this.resume.bind(this);
this.setFocus = this.setFocus.bind(this);
Expand Down Expand Up @@ -618,7 +617,21 @@ class SpatialNavigationService {
this.bindEventHandlers();
if (visualDebug) {
this.visualDebugger = new VisualDebugger(this.writingDirection);
this.startDrawLayouts();
const draw = () => {
requestAnimationFrame(() => {
this.visualDebugger.clearLayouts();
forOwn(this.focusableComponents, (component, focusKey) => {
this.visualDebugger.drawLayout(
component.layout,
focusKey,
component.parentFocusKey
);
});
draw();
});
};

draw();
}
}
}
Expand All @@ -639,24 +652,6 @@ class SpatialNavigationService {
}
}

startDrawLayouts() {
const draw = () => {
requestAnimationFrame(() => {
this.visualDebugger.clearLayouts();
forOwn(this.focusableComponents, (component, focusKey) => {
this.visualDebugger.drawLayout(
component.layout,
focusKey,
component.parentFocusKey
);
});
draw();
});
};

draw();
}

destroy() {
if (this.enabled) {
this.enabled = false;
Expand Down Expand Up @@ -722,14 +717,18 @@ class SpatialNavigationService {
const preventDefaultNavigation =
this.onArrowPress(eventType, keysDetails) === false;

if (this.visualDebugger) {
this.visualDebugger.clear();
}

if (preventDefaultNavigation) {
this.log('keyDownEventListener', 'default navigation prevented');

if (this.visualDebugger) {
this.visualDebugger.clear();
}
} else {
this.onKeyEvent(event);
const direction = findKey(this.getKeyMap(), (codeList) =>
codeList.includes(keyCode)
);

this.smartNavigate(direction, null, { event });
}
};

Expand Down Expand Up @@ -877,19 +876,6 @@ class SpatialNavigationService {
}
}

onKeyEvent(event: KeyboardEvent) {
if (this.visualDebugger) {
this.visualDebugger.clear();
}

const keyCode = SpatialNavigationService.getKeyCode(event);
const direction = findKey(this.getKeyMap(), (codeList) =>
codeList.includes(keyCode)
);

this.smartNavigate(direction, null, { event });
}

/**
* This function navigates between siblings OR goes up by the Tree
* Based on the Direction
Expand Down

0 comments on commit 3306b4c

Please sign in to comment.