Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(ui): standardise api to dip #8427

Open
@mudlabs

Description

@mudlabs

Is your feature request related to a problem? Please describe.
Currently the NativeScript API implements both DP and DIP.

There doesn't appear to be any strategy for when the API returns DP or DIP, and can be one for iOS and another for Android.

Gesture Events are a good example of this.

export function myTouchEvent(args: TouchGestureEventData): void {
    const x: number = args.getX(); // X coordinate in DP
    const y: number = args.getY(); // Y coordinate in DP
    
    const pointer: Pointer = args.getActivePointers()[0];
    pointer.getX(); // X coordinate in DP on iOS, and DIP on Android.
    pointer.getY(); // Y coordinate in DP on iOS, and DIP on Android.
}

export function myPinchEvent(args: PinchGestureEventData): void {
    const x: number = args.getFocusX();// X coordinate in DP on iOS, and DIP on Android.
    const y: number = args.getFocusY();// Y coordinate in DP on iOS, and DIP on Android.
}

export function myPanEvent(args: PanGestureEventData): void {
    const x: number = args.deltaX; // X coordinate in DP on iOS, and DIP on Android.
    const y: number = args.deltaY; // Y coordinate in DP on iOS, and DIP on Android.
}

Describe the solution you'd like
All properties or methods exposed by the NativeScript API that return UI pixel values should be in DIP format.

  • Unless otherwise specified by the property/method name.

If a property or method does specify DP, then it may be a good idea to also provide the DIP alternative directly through the API; to maintain the standardisation.

With a standardised DIP format in place developers can be sure of how values relate to their components. And if they need the DP value all they'll need to do is use layout.toDevicePixels(DIPValue);. Or retrieve it from the underlying native object, which they are likely working with if they need DP values.

Describe alternatives you've considered
Working with the API now, requires you to already know about the platform inconsistencies, of any given end-point, and convert values as needed. Or identify what format is being returned through trial-and-error (testing); and convert as needed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions