androidtitaniumappceleratorappcelerator-titaniumtitanium-alloy

Titanium: Window transitions not working on Android


I want to add window transitions to when opening and closing a window in Android.

Creating transistions for Windows is described in the docs here: http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.Window

foo.js has the following tss file:

"#win": {
    theme: "Theme.AppCompat.Translucent.NoTitleBar",
    fullscreen: false, // To make it heavy-weight (although this should not be needed for > v3.2.0)
}

I have tried the following methods:

Method 1

Alloy.createController('foo')
    .getView().open({
        activityEnterAnimation: Ti.Android.R.anim.fade_in,
        activityExitAnimation: Ti.Android.R.anim.fade_out
    });

The above enter animation works as expected. However, the fade out does not work.

Method 2

Alloy.createController('foo')
    .getView().open({
        activityEnterAnimation: Titanium.UI.Android.TRANSITION_FADE_IN,
        activityExitAnimation: Titanium.UI.Android.TRANSITION_FADE_OUT
    });

Neither fade in or fade out worked

Method 3

"#win[platform=android]": {
    activityEnterAnimation: Titanium.UI.Android.TRANSITION_FADE_IN,
    activityExitAnimation: Titanium.UI.Android.TRANSITION_FADE_OUT,

    // OR
    // activityEnterAnimation: Ti.Android.R.anim.fade_in,
    // activityExitAnimation: Ti.Android.R.anim.fade_out,
}

Neither fade in or fade out worked for either case.


Solution

  • You have two options

    activity*Transitions

    There is currently no way to use the activity*Transitions without a sharedElement. There is an open ticket at https://jira.appcelerator.org/browse/TIMOB-20507 that shows a fix (needs to be adjusted for the first window or add animated:false when opening the first window if you use the fix).

    activity*Animation

    The activity*Animation animations are working like this:

    var win = Ti.UI.createWindow({
        backgroundColor: '#fff'
    });
    
    var win2 = Ti.UI.createWindow({
        backgroundColor: '#f00'
    });
    
    var btn = Ti.UI.createButton({
        title: "open"
    });
    
    win.add(btn);
    
    var btn2 = Ti.UI.createButton({
        title: "close"
    });
    
    win2.add(btn2);
    
    btn2.addEventListener("click", function() {
        win2.close({
            activityExitAnimation: Ti.Android.R.anim.fade_out
        });
    });
    
    btn.addEventListener("click", function() {
        win2.open({
            activityEnterAnimation: Ti.Android.R.anim.fade_in,
            activityExitAnimation: Ti.Android.R.anim.fade_out
        });
    });
    
    win.open();
    

    Tested with 6.1.2.GA and 6.2.2.GA

    Workaround for activity*Transitions

    The activity*Transitions are working like this:

    var win = Ti.UI.createWindow({
        backgroundColor: '#fff',
        activityEnterTransition: Titanium.UI.Android.SLIDE_RIGHT,
        activityExitTransition: Titanium.UI.Android.TRANSITION_EXPLODE
    });
    
    var win2 = Ti.UI.createWindow({
        backgroundColor: '#f00',
       activityEnterTransition: Titanium.UI.Android.SLIDE_RIGHT,
        activityExitTransition: Titanium.UI.Android.TRANSITION_EXPLODE
    });
    // Create label in window A with a unique transitionName.
    var titleInWinA = new Ti.UI.createLabel({
        text: 'Top 10 pics from Mars!',
        left: 70,
        top: 6,
        width: 200,
        height: 30,
        transitionName: 'title',
        color: "#000"
    });
    win.add(titleInWinA);
    
    var btn = Ti.UI.createButton({
        title: "open"
    });
    btn.addEventListener("click", function() {
        win2.addSharedElement(titleInWinA, "title");
        win2.open();
    });
    win.add(btn);
    win.open();
    var titleInWinB = new Ti.UI.createLabel({
        text: 'Top 10 pics from Mars!',
        left: 50,
        top: 10,
        width: 200,
        height: 30,
        transitionName: 'title',
        color: "#000"
    });
    win2.add(titleInWinB);
    

    Keep in mind that they are creation only properties of the window and aren't used as parameters for window.open() like the activity*Animation