Skip to content

chore(core): Got rid of setNative type errors #10768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/core/ui/core/properties/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class Property<T extends ViewBase, U> implements TypedPropertyDescriptor<
public readonly key: symbol;

public readonly getDefault: symbol;
public readonly setNative: any;
public readonly setNative: symbol;

public readonly defaultValueKey: symbol;
public readonly defaultValue: U;
Expand Down Expand Up @@ -397,7 +397,7 @@ export class CoercibleProperty<T extends ViewBase, U> extends Property<T, U> imp
const propertyName = options.name;
const key = this.key;
const getDefault: symbol = this.getDefault;
const setNative: any = this.setNative;
const setNative: symbol = this.setNative;
const defaultValueKey = this.defaultValueKey;
const defaultValue: U = this.defaultValue;

Expand Down Expand Up @@ -612,7 +612,7 @@ export class CssProperty<T extends Style, U> {

public readonly key: symbol;
public readonly getDefault: symbol;
public readonly setNative: any;
public readonly setNative: symbol;
public readonly sourceKey: symbol;
public readonly defaultValueKey: symbol;
public readonly defaultValue: U;
Expand Down Expand Up @@ -879,7 +879,7 @@ export class CssAnimationProperty<T extends Style, U> implements CssAnimationPro
public readonly cssLocalName: string;

public readonly getDefault: symbol;
public readonly setNative: any;
public readonly setNative: symbol;

public readonly register: (cls: { prototype }) => void;

Expand Down
235 changes: 115 additions & 120 deletions packages/core/ui/core/view/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,117 @@ export class View extends ViewCommon {
this.nativeViewProtected.setAlpha(float(value));
}

[accessibilityRoleProperty.setNative](value: AccessibilityRole): void {
this.accessibilityRole = value as AccessibilityRole;
updateAccessibilityProperties(this);

if (SDK_VERSION >= 28) {
this.nativeViewProtected?.setAccessibilityHeading(value === AccessibilityRole.Header);
}
}

[accessibilityLiveRegionProperty.setNative](value: AccessibilityLiveRegion): void {
switch (value as AccessibilityLiveRegion) {
case AccessibilityLiveRegion.Assertive: {
this.nativeViewProtected.setAccessibilityLiveRegion(android.view.View.ACCESSIBILITY_LIVE_REGION_ASSERTIVE);
break;
}
case AccessibilityLiveRegion.Polite: {
this.nativeViewProtected.setAccessibilityLiveRegion(android.view.View.ACCESSIBILITY_LIVE_REGION_POLITE);
break;
}
default: {
this.nativeViewProtected.setAccessibilityLiveRegion(android.view.View.ACCESSIBILITY_LIVE_REGION_NONE);
break;
}
}
}

[accessibilityStateProperty.setNative](value: AccessibilityState): void {
this.accessibilityState = value as AccessibilityState;
updateAccessibilityProperties(this);
}

[horizontalAlignmentProperty.getDefault](): CoreTypes.HorizontalAlignmentType {
return <CoreTypes.HorizontalAlignmentType>org.nativescript.widgets.ViewHelper.getHorizontalAlignment(this.nativeViewProtected);
}
[horizontalAlignmentProperty.setNative](value: CoreTypes.HorizontalAlignmentType) {
const nativeView = this.nativeViewProtected;
const lp: any = nativeView.getLayoutParams() || new org.nativescript.widgets.CommonLayoutParams();
const gravity = lp.gravity;
const weight = lp.weight;
// Set only if params gravity exists.
if (gravity !== undefined) {
switch (value) {
case 'left':
lp.gravity = GRAVITY_LEFT | (gravity & VERTICAL_GRAVITY_MASK);
if (weight < 0) {
lp.weight = -2;
}
break;
case 'center':
lp.gravity = GRAVITY_CENTER_HORIZONTAL | (gravity & VERTICAL_GRAVITY_MASK);
if (weight < 0) {
lp.weight = -2;
}
break;
case 'right':
lp.gravity = GRAVITY_RIGHT | (gravity & VERTICAL_GRAVITY_MASK);
if (weight < 0) {
lp.weight = -2;
}
break;
case 'stretch':
lp.gravity = GRAVITY_FILL_HORIZONTAL | (gravity & VERTICAL_GRAVITY_MASK);
if (weight < 0) {
lp.weight = -1;
}
break;
}
nativeView.setLayoutParams(lp);
}
}

[verticalAlignmentProperty.getDefault](): CoreTypes.VerticalAlignmentType {
return <CoreTypes.VerticalAlignmentType>org.nativescript.widgets.ViewHelper.getVerticalAlignment(this.nativeViewProtected);
}
[verticalAlignmentProperty.setNative](value: CoreTypes.VerticalAlignmentType) {
const nativeView = this.nativeViewProtected;
const lp: any = nativeView.getLayoutParams() || new org.nativescript.widgets.CommonLayoutParams();
const gravity = lp.gravity;
const height = lp.height;
// Set only if params gravity exists.
if (gravity !== undefined) {
switch (value) {
case 'top':
lp.gravity = GRAVITY_TOP | (gravity & HORIZONTAL_GRAVITY_MASK);
if (height < 0) {
lp.height = -2;
}
break;
case 'middle':
lp.gravity = GRAVITY_CENTER_VERTICAL | (gravity & HORIZONTAL_GRAVITY_MASK);
if (height < 0) {
lp.height = -2;
}
break;
case 'bottom':
lp.gravity = GRAVITY_BOTTOM | (gravity & HORIZONTAL_GRAVITY_MASK);
if (height < 0) {
lp.height = -2;
}
break;
case 'stretch':
lp.gravity = GRAVITY_FILL_VERTICAL | (gravity & HORIZONTAL_GRAVITY_MASK);
if (height < 0) {
lp.height = -1;
}
break;
}
nativeView.setLayoutParams(lp);
}
}

[testIDProperty.setNative](value: string) {
this.setAccessibilityIdentifier(this.nativeViewProtected, value);
}
Expand All @@ -833,27 +944,17 @@ export class View extends ViewCommon {
this.setAccessibilityIdentifier(this.nativeViewProtected, value);
}

// @ts-expect-error
[accessibilityRoleProperty.setNative](value: AccessibilityRole): void {
this.accessibilityRole = value;
updateAccessibilityProperties(this);

if (SDK_VERSION >= 28) {
this.nativeViewProtected?.setAccessibilityHeading(value === AccessibilityRole.Header);
}
}

[accessibilityValueProperty.setNative](): void {
[accessibilityValueProperty.setNative](value: string): void {
this._androidContentDescriptionUpdated = true;
updateContentDescription(this);
}

[accessibilityLabelProperty.setNative](): void {
[accessibilityLabelProperty.setNative](value: string): void {
this._androidContentDescriptionUpdated = true;
updateContentDescription(this);
}

[accessibilityHintProperty.setNative](): void {
[accessibilityHintProperty.setNative](value: string): void {
this._androidContentDescriptionUpdated = true;
updateContentDescription(this);
}
Expand All @@ -866,31 +967,7 @@ export class View extends ViewCommon {
}
}

// @ts-expect-error
[accessibilityLiveRegionProperty.setNative](value: AccessibilityLiveRegion): void {
switch (value) {
case AccessibilityLiveRegion.Assertive: {
this.nativeViewProtected.setAccessibilityLiveRegion(android.view.View.ACCESSIBILITY_LIVE_REGION_ASSERTIVE);
break;
}
case AccessibilityLiveRegion.Polite: {
this.nativeViewProtected.setAccessibilityLiveRegion(android.view.View.ACCESSIBILITY_LIVE_REGION_POLITE);
break;
}
default: {
this.nativeViewProtected.setAccessibilityLiveRegion(android.view.View.ACCESSIBILITY_LIVE_REGION_NONE);
break;
}
}
}

// @ts-expect-error
[accessibilityStateProperty.setNative](value: AccessibilityState): void {
this.accessibilityState = value;
updateAccessibilityProperties(this);
}

[accessibilityMediaSessionProperty.setNative](): void {
[accessibilityMediaSessionProperty.setNative](value: string): void {
updateAccessibilityProperties(this);
}

Expand Down Expand Up @@ -974,88 +1051,6 @@ export class View extends ViewCommon {
nativeView.setStateListAnimator(stateListAnimator);
}

[horizontalAlignmentProperty.getDefault](): CoreTypes.HorizontalAlignmentType {
return <CoreTypes.HorizontalAlignmentType>org.nativescript.widgets.ViewHelper.getHorizontalAlignment(this.nativeViewProtected);
}
// @ts-expect-error
[horizontalAlignmentProperty.setNative](value: CoreTypes.HorizontalAlignmentType) {
const nativeView = this.nativeViewProtected;
const lp: any = nativeView.getLayoutParams() || new org.nativescript.widgets.CommonLayoutParams();
const gravity = lp.gravity;
const weight = lp.weight;
// Set only if params gravity exists.
if (gravity !== undefined) {
switch (value) {
case 'left':
lp.gravity = GRAVITY_LEFT | (gravity & VERTICAL_GRAVITY_MASK);
if (weight < 0) {
lp.weight = -2;
}
break;
case 'center':
lp.gravity = GRAVITY_CENTER_HORIZONTAL | (gravity & VERTICAL_GRAVITY_MASK);
if (weight < 0) {
lp.weight = -2;
}
break;
case 'right':
lp.gravity = GRAVITY_RIGHT | (gravity & VERTICAL_GRAVITY_MASK);
if (weight < 0) {
lp.weight = -2;
}
break;
case 'stretch':
lp.gravity = GRAVITY_FILL_HORIZONTAL | (gravity & VERTICAL_GRAVITY_MASK);
if (weight < 0) {
lp.weight = -1;
}
break;
}
nativeView.setLayoutParams(lp);
}
}

[verticalAlignmentProperty.getDefault](): CoreTypes.VerticalAlignmentType {
return <CoreTypes.VerticalAlignmentType>org.nativescript.widgets.ViewHelper.getVerticalAlignment(this.nativeViewProtected);
}
// @ts-expect-error
[verticalAlignmentProperty.setNative](value: CoreTypes.VerticalAlignmentType) {
const nativeView = this.nativeViewProtected;
const lp: any = nativeView.getLayoutParams() || new org.nativescript.widgets.CommonLayoutParams();
const gravity = lp.gravity;
const height = lp.height;
// Set only if params gravity exists.
if (gravity !== undefined) {
switch (value) {
case 'top':
lp.gravity = GRAVITY_TOP | (gravity & HORIZONTAL_GRAVITY_MASK);
if (height < 0) {
lp.height = -2;
}
break;
case 'middle':
lp.gravity = GRAVITY_CENTER_VERTICAL | (gravity & HORIZONTAL_GRAVITY_MASK);
if (height < 0) {
lp.height = -2;
}
break;
case 'bottom':
lp.gravity = GRAVITY_BOTTOM | (gravity & HORIZONTAL_GRAVITY_MASK);
if (height < 0) {
lp.height = -2;
}
break;
case 'stretch':
lp.gravity = GRAVITY_FILL_VERTICAL | (gravity & HORIZONTAL_GRAVITY_MASK);
if (height < 0) {
lp.height = -1;
}
break;
}
nativeView.setLayoutParams(lp);
}
}

[rotateProperty.setNative](value: number) {
org.nativescript.widgets.ViewHelper.setRotate(this.nativeViewProtected, float(value));
}
Expand Down
5 changes: 2 additions & 3 deletions packages/core/ui/image/index.ios.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ImageBase, stretchProperty, imageSourceProperty, tintColorProperty, srcProperty, iosSymbolEffectProperty, ImageSymbolEffect, ImageSymbolEffects, iosSymbolScaleProperty } from './image-common';
import { ImageSource, iosSymbolScaleType } from '../../image-source';
import { ImageSource } from '../../image-source';
import { ImageAsset } from '../../image-asset';
import { Color } from '../../color';
import { Trace } from '../../trace';
Expand Down Expand Up @@ -219,8 +219,7 @@ export class Image extends ImageBase {
}
}

// @ts-expect-error
[iosSymbolScaleProperty.setNative](value: iosSymbolScaleType) {
[iosSymbolScaleProperty.setNative](value: string) {
// reset src to configure scale
this._setSrc(this.src);
}
Expand Down
5 changes: 2 additions & 3 deletions packages/core/ui/search-bar/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { isUserInteractionEnabledProperty, isEnabledProperty } from '../core/vie
import { ad } from '../../utils';
import { Color } from '../../color';
import { colorProperty, backgroundColorProperty, backgroundInternalProperty, fontInternalProperty, fontSizeProperty } from '../styling/style-properties';
import { Background } from '../styling/background';

export * from './search-bar-common';

Expand Down Expand Up @@ -227,22 +228,20 @@ export class SearchBar extends SearchBarBase {
[backgroundInternalProperty.getDefault](): any {
return null;
}
[backgroundInternalProperty.setNative](value: any) {
[backgroundInternalProperty.setNative](value: android.graphics.drawable.Drawable | Background) {
//
}

[textProperty.getDefault](): string {
return '';
}
// @ts-expect-error
[textProperty.setNative](value: string) {
const text = value === null || value === undefined ? '' : value.toString();
this.nativeViewProtected.setQuery(text, false);
}
[hintProperty.getDefault](): string {
return null;
}
// @ts-expect-error
[hintProperty.setNative](value: string) {
if (value === null || value === undefined) {
this.nativeViewProtected.setQueryHint(null);
Expand Down
4 changes: 1 addition & 3 deletions packages/core/ui/search-bar/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,13 @@ export class SearchBar extends SearchBarBase {
[backgroundInternalProperty.getDefault](): any {
return null;
}
[backgroundInternalProperty.setNative](value: any) {
[backgroundInternalProperty.setNative](value: UIColor) {
//
}

[textProperty.getDefault](): string {
return '';
}
// @ts-expect-error
[textProperty.setNative](value: string) {
const text = value === null || value === undefined ? '' : value.toString();
this.ios.text = text;
Expand All @@ -174,7 +173,6 @@ export class SearchBar extends SearchBarBase {
[hintProperty.getDefault](): string {
return '';
}
// @ts-expect-error
[hintProperty.setNative](value: string) {
this._updateAttributedPlaceholder();
}
Expand Down
1 change: 0 additions & 1 deletion packages/core/ui/styling/style-properties.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export const minWidthProperty: CssProperty<Style, CoreTypes.dip | CoreTypes.Leng
export const minHeightProperty: CssProperty<Style, CoreTypes.dip | CoreTypes.LengthDipUnit | CoreTypes.LengthPxUnit>;
export const widthProperty: CssAnimationProperty<Style, CoreTypes.PercentLengthType>;
export const heightProperty: CssAnimationProperty<Style, CoreTypes.PercentLengthType>;
export const lineHeightProperty: CssProperty<Style, number>;
export const marginProperty: ShorthandProperty<Style, string | CoreTypes.PercentLengthType>;
export const marginLeftProperty: CssProperty<Style, CoreTypes.PercentLengthType>;
export const marginRightProperty: CssProperty<Style, CoreTypes.PercentLengthType>;
Expand Down
Loading