Skip to content

Commit

Permalink
respect hasPrefferedFocus property on component even it's added not i…
Browse files Browse the repository at this point in the history
…n first render cycle
  • Loading branch information
aurimasmi committed Oct 26, 2023
1 parent c1f2d95 commit b5ca64e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 7 additions & 2 deletions packages/create/src/focusManager/model/screen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,14 @@ class Screen extends FocusModel {

public setFocus(model: View | null) {
if (model) {
CoreManager.getCurrentFocus()?.getScreen()?.onBlur?.();
const screenIsDifferent = CoreManager.getCurrentFocus()?.getScreen()?.getId() !== model.getScreen()?.getId();
if (screenIsDifferent) {
CoreManager.getCurrentFocus()?.getScreen()?.onBlur?.();
}
CoreManager.executeFocus(model);
model.getScreen()?.onFocus();
if (screenIsDifferent) {
model.getScreen()?.onFocus();
}
if (model.getParent()?.getId() !== model.getScreen()?.getId()) {
model.getParent()?.onFocus();
}
Expand Down
9 changes: 6 additions & 3 deletions packages/create/src/focusManager/model/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class View extends FocusModel {
private _horizontalContentContainerGap = 0;
private _repeatContext:
| {
focusContext: FocusModel;
index: number;
}
focusContext: FocusModel;
index: number;
}
| undefined;

private _onPress?: () => void;
Expand Down Expand Up @@ -124,6 +124,9 @@ class View extends FocusModel {
private async _onLayout() {
await measureAsync({ model: this });
this.getScreen()?.removeComponentFromPendingLayoutMap(this.getId());
if (this.hasPreferredFocus()) {
this.getScreen()?.setFocus(this);
}
}

// END EVENTS
Expand Down

0 comments on commit b5ca64e

Please sign in to comment.