Skip to content
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

Crashes if I switch from win to navController in centerView #2

Closed
sindresorhus opened this issue Sep 17, 2013 · 20 comments
Closed

Crashes if I switch from win to navController in centerView #2

sindresorhus opened this issue Sep 17, 2013 · 20 comments
Labels

Comments

@sindresorhus
Copy link

When I programmatically switch out a navController in centerView with a plain window it crashes on iOS 7 and Ti SDK 3.1.3.v20130910153050.

app.js

'use strict';
var NappDrawer = require('dk.napp.drawer');

Ti.UI.backgroundColor = 'white';

function createLeftWindow() {
    var win = Ti.UI.createWindow();
    var menuListView = Ti.UI.createListView();
    var menuListViewSection = Ti.UI.createListSection();

    menuListViewSection.items = [{
        properties: {
            title: 'win',
            itemId: 'win'
        }
    }, {
        properties: {
            title: 'nav',
            itemId: 'nav'
        }
    }];

    menuListView.addEventListener('itemclick', function (e) {
        mainWin.centerWindow = require(e.itemId)();
    });

    menuListView.sections = [menuListViewSection];
    win.add(menuListView);

    return win;
}

var mainWin = NappDrawer.createDrawer({
    leftWindow: createLeftWindow(),
    centerWindow: require('win')()
});

mainWin.open();
mainWin.toggleLeftWindow();

nav.js

'use strict';
module.exports = function () {
    var win = Ti.UI.createWindow({
        title: 'nav',
        backgroundColor: 'white'
    });

    var navController = Ti.UI.iPhone.createNavigationGroup({
        window: win
    });

    return navController;
};

win.js

'use strict';
module.exports = function () {
    var win = Ti.UI.createWindow({
        title: 'nav',
        backgroundColor: 'white',
    });

    return win;
};
@sindresorhus
Copy link
Author

This also happens when I try to switch from a NavigationWindow (new in Ti 3.1.3) to NavigationGroup or Window.

@moshemarciano
Copy link

also when switching from a TabGroup to a Window or from a TabGroup to a NavigationWindow, always crashing when toggling the center window from one window to the other. sometimes it will get by 1-3 switches and then crash.

using Alloy 1.2.2/iOS7/Ti SDK 3.1.3.GA

index.js

Alloy.Globals.win_blue  = Alloy.createController('bluewin').getView();
Alloy.Globals.win_green = Alloy.createController('greenwin').getView();

var NappDrawerModule = require('dk.napp.drawer');

var drawer = NappDrawerModule.createDrawer({
    leftWindow: Alloy.createController('sidemenu').getView(),
    centerWindow: Alloy.Globals.win_green,
    closeDrawerGestureMode: NappDrawerModule.CLOSE_MODE_ALL,
    openDrawerGestureMode: NappDrawerModule.OPEN_MODE_ALL,
    leftDrawerWidth: 200
});

Alloy.Globals.drawer = drawer;
drawer.open();
drawer.setAnimationMode(NappDrawerModule.ANIMATION_PARALLAX_FACTOR_3);  

sidemenu.xml

<Alloy>
    <Window id="sidemenu" title="Side Menu" backgroundColor="white">
        <Button id="green" color="green" onClick="doClick_green">Green</Button>
        <Button id="blue" color="blue" onClick="doClick_blue">Blue</Button>
    </Window>
</Alloy>

sidemenu.js

function doClick_blue(e) {
    Alloy.Globals.win_blue.open();     // this works
    Alloy.Globals.drawer.centerWindow = Alloy.Globals.win_blue;      // this crashes
}

greenwin.xml

<Alloy>
        <Window id="green_win" title="Green Window" backgroundColor="green">
            <Button color="black" style="bottom:30" onClick="closeWindow">Close Window</Button>
        </Window>
</Alloy>

bluewin.xml

<Alloy>
    <Window id="blue_win" title="Blue Window" backgroundColor="white">
        <Button color="black" style="bottom:30" >Blue</Button>
            <Button id="green" color="#1B65FF" style="bottom:100" >Green</Button>
    </Window>
</Alloy>

@viezel
Copy link
Owner

viezel commented Oct 6, 2013

try this and let me know: https://github.com/viezel/NappDrawer/releases/tag/1.1.0
it should fix it.

@sindresorhus
Copy link
Author

still crashes when switching from a NavigationGroup to a Window

@viezel
Copy link
Owner

viezel commented Oct 8, 2013

Try with navigation window

@sindresorhus
Copy link
Author

sorry, I meant NavigationWindow

@viezel
Copy link
Owner

viezel commented Oct 8, 2013

works fine here..

@sindresorhus
Copy link
Author

@viezel works fine for you using my testcase? because it's also crashing for me.
(just replace the Ti.UI.iPhone.createNavigationGroup with Ti.UI.iOS.createNavigationWindow)

@viezel
Copy link
Owner

viezel commented Oct 8, 2013

im not using your testcase.. sorry, open source != support :)
I did some testing with my own code, and that works fine. Thereby im not saying there are no bugs.

@moshemarciano
Copy link

I can confirm that it still crashes, with the Alloy testcase I detailed above.
I open the drawer, click one button in the drawer, the center view is switched, click on the second button, which sets the center view to the original, and the app crashes.

[INFO] : [object DkNappDrawerModule] loaded
[ERROR] : An error occurred running the iOS Simulator
[ERROR] : [DEBUG] using retina iphone retina ios 7

@jonatansberg
Copy link

I was also experiencing this issue. You need to make sure you only use NavigationGroups with versions 1.0.3 and below, while 1.1 will only work with NavigationWindows.

Corresponding diff:
dd53c83#diff-5cc8f045e3468ad390e389d26aa781a8L30

@moshemarciano
Copy link

@mrlundis I am using 1.1 with an Alloy project (see source on the top of this thread), NavigationWindow only and it crashes when I set the center view more than once.

@jonatansberg
Copy link

@moshemarciano As far as I can tell from the source only regular Windows and NavigationWindows are supported as of now. TabGroups and other window types might need additional logic to access the proper native controllers.

@moshemarciano
Copy link

@mrlundis I am using a navigationWindow, still crashing

'''XML

<NavigationWindow platform="ios" id="welcomeWin">

    <Window id="win" title="Add">

    </Window>

</NavigationWindow>

'''

@jonatansberg
Copy link

@moshemarciano Okay, my bad. Try opening the generated Xcode project and run the application from there, that way you can get a proper stack trace and might be able to figure out whats causing the crash. If you also open up the NappDrawer module project you'll be able to step through the full source from within your own application which is very useful for debugging.

Other than that I can't be of much further help.

Good luck!

@janhelleman
Copy link

This doesn't happen to me when using NavigationWindow instead of NavigationGroup. Tested in simulator with 3.1.3.GA

@moshemarciano
Copy link

@janhelleman can you share the test code? maybe I am doing something wrong. is it also Alloy based?

@janhelleman
Copy link

Let's see. index.js:

var leftMenu = Alloy.createController('leftMenu').getView();
var rightMenu = Alloy.createController('rightMenu').getView();
var center = Alloy.createController('center').getView();

var drawer = Alloy.Globals.drawer = NappDrawerModule.createDrawer({
        fullscreen:false, 
        leftWindow: leftMenu,
        rightWindow: rightMenu,
        centerWindow: center,
        fading: 0.2, // 0-1
        parallaxAmount: 0.2, //0-1
        shadowWidth:"40dp", 
        leftDrawerWidth: "200dp",
        rightDrawerWidth: "200dp",
        animationMode: NappDrawerModule.ANIMATION_NONE,
        closeDrawerGestureMode: OS_IOS ? NappDrawerModule.CLOSE_MODE_ALL : NappDrawerModule.MODE_MARGIN,
        openDrawerGestureMode: OS_IOS ? NappDrawerModule.OPEN_MODE_ALL : NappDrawerModule.MODE_ALL
});

..
Alloy.Globals.openWindow = function(view)
{
    if(!OS_IOS)
    {
        Alloy.Globals.openViews.push(view);
        drawer.setCenterWindow(view);
    }
    else
    {
        if(view.isBase)
        {
            //alert('test ' + view);
            drawer.setCenterWindow(view);
            Alloy.Globals.navigationWindow = view;
        }
        else
        {
            Alloy.Globals.navigationWindow.openWindow(view);
        }
    }
};

center.xml

<Alloy>
    <View class="container" platform='android'>
        <Label id='clicke'>test</Label>
        <Label id='sometext' top='0'>test</Label>
    </View>
    <NavigationWindow platform='ios' id='navgroup'>
        <Window class="container">
            <Label id='clicke'>test</Label>
            <Label id='sometext' top='0'>test</Label>
        </Window>
    </NavigationWindow>

</Alloy>

centertwo (opened on clicke)

<Alloy>
    <View class="container" platform='android'>
            <Label id='clicke'>test</Label>
    </View>
    <Window class="container" platform='ios'>
            <Label id='clicke'>test</Label>
    </Window>
</Alloy>

center three (opened on clicke centertwo, has isBase true)

<Alloy>
    <View class="container" platform='android'>
        <Label id='clicke'>test</Label>
        <Label id='sometext' top='0'>test</Label>
    </View>
    <NavigationWindow platform='ios' id='navgroup'>
        <Window class="container">
            <Label id='clicke'>test</Label>
            <Label id='sometext' top='0'>test</Label>
        </Window>
    </NavigationWindow>

</Alloy>

in the clicke functions:

$.clicke.addEventListener('click', function(e)
{
    var view = Alloy.createController('center').getView();
    Alloy.Globals.openWindow(view);
});

I think this is most of it. As you can see it uses navigationwindows instead of groups. It switches (depending on what platform it caches the previous views) in index.js at Alloy.Globals.openWindow().

Is this enough to go on?

Kind regards,
Jan

@janhelleman
Copy link

Also, if from NavigationWindow to NavigationWindow might work, but NavigationWindow to Window (or visa versa) doesn't work, you might consider using a NavigationWindow for the Window without the navbar.

@atypical
Copy link

For Alloy - the solve seems to be setting drawer views as < Window > and the center or main view as: < NavigationWindow platform="ios" id="" > < Window id="loginModal" > < /Window > < /NavigationWindow >

Any views you load into the center/main view should be < NavigationWindow > and drawer views should just be < Window >

//MD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants