Android Object Animator


#1

Hi,

I’m currently working on a UI plugin for a custom View that does native drawing for it’s respective platform. I have been experiencing some difficulties getting android’s object animator working and was wondering if anyone could give some insight into how custom properties are dealt with when extending native views using the NativeScript apis.

I have a requirement for keeping all code within the plugin in typescript, so please bear this in mind; I do not want to bundle pre-compiled java / objective-c views.

Having said that, I’m basically trying to achieve the following, using NativeScript’s extend functionality;

Java:

class SomeClass extends View {
    float someCustomProperty = 0;
    ObjectAnimator animator;

    ...

    void someCustomFunc(float newValue) {
        this.animator = ObjectAnimator.ofFloat(this, "someCustomProperty", someCustomProperty, newValue);
        this.animator.setDuration(5);
        this.animator.setInterpolator(new AccelerateDecelerateInterpolator());
        this.animator.start();
    }

    void setSomeCustomProperty(float newValue) {
        this.someCustomProperty = newValue;
        this.invalidate();
    }
}

Typescript:

export class SomeClass extends android.view.View {
    someCustomProperty = new java.lang.Float(0);
    animator: android.animation.ObjectAnimator;

    ...

    someCustomFunc(newValue: number) {
        this.animator = android.animation.ObjectAnimator.ofFloat(this, "someCustomProperty", [newValue]);
        this.animator.setDuration(5);
        this.animator.setInterpolator(new android.view.animation.AccelerateDecelerateInterpolator());
        this.animator.start();
    }

    setSomeCustomProperty(newValue: number) {
        this.someCustomProperty = new java.lang.Float(newValue);
        this.invalidate();
    }
}

Are generated property names at play here? Any insight would be greatly appreciated, thanks.


#2

TypeScript/JavaScript properties are kept into JavaScript and no static/member fields are generated for the Java class.

Having said that, I don’t think you’ll be able to use the ofType ObjectAnimator static methods that require a string with a class field name.


#3

Thanks, I’ll have to think of another approach.