Skip to content

Commit 1222d90

Browse files
committed
feat: global clearFocus and requestFocus
1 parent 1d36644 commit 1222d90

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/core/index.android.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ class ViewWithElevationAndRipple extends View {
154154
}
155155
}
156156
}
157+
public requestFocus() {
158+
this.focus();
159+
}
160+
public clearFocus() {
161+
handleClearFocus(this.nativeViewProtected);
162+
ad.dismissSoftInput(this.nativeViewProtected);
163+
}
157164

158165
getDefaultElevation(): number {
159166
const result = this instanceof Button ? 2 : 0;

src/core/index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { Color } from '@nativescript/core';
22

3+
declare module '@nativescript/core/ui/core/view' {
4+
interface View {
5+
clearFocus();
6+
requestFocus();
7+
}
8+
}
9+
310
export interface TypographyOptions {
411
fontFamily?: string;
512
fontSize?: number;

src/core/index.ios.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ export class Themer {
106106

107107
export const themer = new Themer();
108108

109-
export function install() {
110-
111-
}
109+
export function install() {}
112110

113111
export function getRippleColor(color: string | Color): UIColor {
114112
if (color) {
@@ -190,6 +188,13 @@ class ViewWithElevationAndRipple extends View {
190188
this.shadowLayer.elevation = elevation;
191189
}
192190
}
191+
192+
public requestFocus() {
193+
this.focus();
194+
}
195+
public clearFocus() {
196+
this.nativeViewProtected.resignFirstResponder();
197+
}
193198
[rippleColorProperty.setNative](color: Color) {
194199
this.getOrCreateRippleController();
195200
this.inkTouchController.rippleView.rippleColor = getRippleColor(color);

0 commit comments

Comments
 (0)