Repository: NativeScript/NativeScript
File: tns-core-modules/ui/core/view/view.android.ts (TypeScript)

Code before:
    [visibilityProperty.setNative](value: Visibility) {
        switch (value) {
            case "visible":
                this.nativeViewProtected.setVisibility(android.view.View.VISIBLE);
                break;
            case "hidden":
                this.nativeViewProtected.setVisibility(android.view.View.INVISIBLE);
                break;
            case "collapse":
                this.nativeViewProtected.setVisibility(android.view.View.GONE);
                break;
            default:
                throw new Error(`Invalid visibility value: ${value}. Valid values are: visible, hidden, collapse.`);
        }
    }

    [opacityProperty.getDefault](): number {
        return this.nativeViewProtected.getAlpha();
    }
    [opacityProperty.setNative](value: number) {
        this.nativeViewProtected.setAlpha(float(value));
    }

    [elevationProperty.getDefault](): number {
        console.log("elevationProperty.getDefault");
        return undefined;
    }

    [elevationProperty.setNative](value: number) {
        if (sdkVersion() < 21) { return; }
        console.log("elevationProperty.setNative, value: " + value);
        const nativeView: any = this.nativeViewProtected;
        if (value !== undefined) {
            if (this._originalElevation === undefined) {
                this._originalElevation = nativeView.getElevation();
            }
            nativeView.setElevation(layout.toDevicePixels(value));
        } else {
            // reset to original value
            if (this._originalElevation !== undefined) {
                nativeView.setElevation(this._originalElevation);
            }
        }
        this._refreshStateListAnimator();
    }

    [androidPressedZProperty.getDefault](): number {
        console.log("androidPressedZProperty.getDefault");
        return undefined;
    }


Review comment (suggestion):
Let's replace the `undefined` usages with `null` (and the `undefined` checks with != null).

Code after:
            default:
                throw new Error(`Unsupported android.view.View visibility: ${nativeVisibility}. Currently supported values are android.view.View.VISIBLE, android.view.View.INVISIBLE, android.view.View.GONE.`);
        }
    }
    [visibilityProperty.setNative](value: Visibility) {
        switch (value) {
            case "visible":
                this.nativeViewProtected.setVisibility(android.view.View.VISIBLE);
                break;
            case "hidden":
                this.nativeViewProtected.setVisibility(android.view.View.INVISIBLE);
                break;
            case "collapse":
                this.nativeViewProtected.setVisibility(android.view.View.GONE);
                break;
            default:
                throw new Error(`Invalid visibility value: ${value}. Valid values are: visible, hidden, collapse.`);
        }
    }

    [opacityProperty.getDefault](): number {
        return this.nativeViewProtected.getAlpha();
    }
    [opacityProperty.setNative](value: number) {
        this.nativeViewProtected.setAlpha(float(value));
    }

    [androidElevationProperty.getDefault](): number {
        if (sdkVersion() < 21) {
            return 0;
        }

        // NOTE: overriden in Button implementation as for widgets with StateListAnimator (Button)
        // nativeView.getElevation() returns 0 at the time of the getDefault() query
        return layout.toDeviceIndependentPixels((<any>this.nativeViewProtected).getElevation());
    }
    [androidElevationProperty.setNative](value: number) {
        if (sdkVersion() < 21) {
            return;
        }

        this.refreshStateListAnimator();
    }

    [androidDynamicElevationOffsetProperty.getDefault](): number {
        return 0;
    }
    [androidDynamicElevationOffsetProperty.setNative](value: number) {
        if (sdkVersion() < 21) {
            return;
        }