Skip to content

Commit

Permalink
[7_0_X][TIMOB-20332] Android: Closing a Ti.UI.TabGroup that contains …
Browse files Browse the repository at this point in the history
…a ti.map view crashes the app (#9678)

* Fix FragmentManager reference when TiUIFragment is in TabGroup.

* Add unit test.

* Try to fix test
  • Loading branch information
ypbnv authored and sgtcoolguy committed Dec 15, 2017
1 parent b13a1d2 commit 64afb38
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.appcelerator.titanium.view;

import org.appcelerator.kroll.common.TiMessenger;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
Expand Down Expand Up @@ -79,7 +78,7 @@ public void release()
FragmentTransaction transaction = null;
Fragment tabFragment = fragmentManager.findFragmentById(android.R.id.tabcontent);
if (tabFragment != null) {
FragmentManager childManager = tabFragment.getChildFragmentManager();
FragmentManager childManager = fragment.getActivity().getSupportFragmentManager();
transaction = childManager.beginTransaction();
} else {
transaction = fragmentManager.beginTransaction();
Expand Down
56 changes: 56 additions & 0 deletions tests/Resources/ti.ui.tabgroup.addontest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Appcelerator Titanium Mobile
* Copyright (c) 2011-Present by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
/* eslint-env mocha */
/* global Ti */
/* eslint no-unused-expressions: "off" */
'use strict';
var should = require('./utilities/assertions');

describe('Titanium.UI.Tabgroup', function () {
var tabGroup,
tab;

afterEach(function () {
if (tab && tabGroup) {
tabGroup.removeTab(tab);
}
tab = null;
});

it('Remove MapView from TabGroup', function (finish) {
// create tab group
var win = Ti.UI.createWindow({
title:'Tab 1',
backgroundColor:'#fff'
}),
Map = require('ti.map'),
mapview;

this.timeout(10000);

tabGroup = Ti.UI.createTabGroup();
tab = Ti.UI.createTab({
title:'Tab 1',
window: win
});

mapview = Map.createView({ top: 0, height: '80%' });
// when the map is done loading, close the tab group
mapview.addEventListener('complete', function () {
tabGroup.close();
});

win.add(mapview);
tabGroup.addTab(tab);
tabGroup.open();

// when the tab group is closed, finish the test
tabGroup.addEventListener('close', function () {
finish();
});
});
});

0 comments on commit 64afb38

Please sign in to comment.