Skip to content

feat(android): change from Fragment to a normal View#703

Open
m1ga wants to merge 12 commits intomasterfrom
androidView
Open

feat(android): change from Fragment to a normal View#703
m1ga wants to merge 12 commits intomasterfrom
androidView

Conversation

@m1ga
Copy link
Copy Markdown
Contributor

@m1ga m1ga commented May 13, 2025

I think it is currently the only module that uses Fragments instead of a normal view. This had some issues before (ListView header) and it will fix tidev/titanium-sdk#14214

Also matches the same library versions as #678 (merge first for the action fixes).

Tested:

ti.map-android-6.0.0.zip
(updated 26/04/16 - 19:30)

Lite mode check:

var win = Titanium.UI.createWindow({
	layout:"vertical"
});
var Map = require('ti.map');

function createMap(liteMode) {
	var map = Map.createView({
		top: 10,
		right: 0,
		width: Ti.UI.FILL,
		height: 200,
		liteMode: liteMode,
		region: {
			zoom: 10,
			latitude: 46.893234,
			longitude: 1.346569,
		}
	});
	var an = Map.createAnnotation({
		title: 'Title',
		latitude: 46.893234,
		longitude: 1.346569,
	})
	map.addAnnotation(an);
	win.add(map);
}

createMap(true);	// liteMode map
createMap(false);	// normal map
win.open();

ListView Header/Footer example

var Map = require('ti.map');

var map = Map.createView({
	top: 10,
	right: 0,
	width: Ti.UI.FILL,
	height: 200,
	region: {
		zoom: 10,
		latitude: 46.893234,
		longitude: 1.346569,
	}
});
var map2 = Map.createView({
	top: 10,
	right: 0,
	width: Ti.UI.FILL,
	height: 200,
	region: {
		zoom: 10,
		latitude: 46.893234,
		longitude: 1.346569,
	}
});
var an = Map.createAnnotation({
	title: 'Title',
	latitude: 46.893234,
	longitude: 1.346569,
})
map.addAnnotation(an);

var win = Ti.UI.createWindow();
var listView = Ti.UI.createListView();
var sections = [];

var fruitDataSet = [];
for (var i = 0; i < 100; i++) {
	fruitDataSet.push({properties: {
		title: "t" + i
	}});
}
var fruitSection = Ti.UI.createListSection({
	headerView: map,
	items: fruitDataSet
});
sections.push(fruitSection);

listView.sections = sections;
win.add(listView);
win.open();

var fishDataSet = [{
		properties: {
			title: 'Cod'
		}
	}
];
var fishSection = Ti.UI.createListSection({
	footerView: map2,
	items: fishDataSet
});
listView.appendSection(fishSection);

Copy link
Copy Markdown
Contributor

@hansemannn hansemannn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Important: the MapView refactor only forwards onResume() and onDestroy(), but not onStart(), onPause(), onStop(), low-memory, or saved-state callbacks. See android/src/ti/map/TiUIMapView.java:96, android/src/ti/map/TiUIMapView.java:1443, and android/src/ti/map/ViewProxy.java:125. titanium-sdk shows these lifecycle hooks are available on proxies, so this is a real integration gap, not a platform limitation. The result is likely leaked map resources and broken restore/background behavior after activity pause/recreate. Fix by forwarding the full activity lifecycle to MapView, and if recreation is expected to preserve state, wire instance-state callbacks through to MapView.onCreate(savedState) / onSaveInstanceState().

  2. Important: liteMode and zOrderOnTop were creation-time options before this change, but the new code always constructs a plain new MapView(...) and only reads liteMode later as a boolean flag. See android/src/ti/map/TiUIMapView.java:96 and android/src/ti/map/TiUIMapView.java:250. That means both public properties are now effectively ignored, which is a behavior regression. Fix by building GoogleMapOptions from the proxy properties before creating the MapView.

@hansemannn
Copy link
Copy Markdown
Contributor

Thanks for the updates! Two issues are still open:

  1. MapView still never gets a real onResume() after backgrounding. ViewProxy forwards onStart(), onPause(), and onStop(), but there is still no onResume(Activity) override, so the map can be paused/stopped and never resumed.
  2. Saved-state handling is still wrong. TiUIMapView calls mMapView.onCreate(null) in the constructor and may call mMapView.onCreate(savedState) again later from onResume(). That gives one MapView instance two onCreate() calls, and there is still no proper onSaveInstanceState() bridge even though Titanium core supports it.

The earlier liteMode/zOrderOnTop regression and the iOS workflow SDK mismatch look fixed.

@m1ga m1ga marked this pull request as draft April 16, 2026 09:33
@m1ga
Copy link
Copy Markdown
Contributor Author

m1ga commented Apr 16, 2026

Thanks for the feedback, I'll do some more tests here 👍

@hansemannn hansemannn marked this pull request as ready for review April 16, 2026 10:59
Copy link
Copy Markdown
Contributor

@hansemannn hansemannn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code-wise, this looks very well now! Feel free to merge once functionally tested.

@m1ga
Copy link
Copy Markdown
Contributor Author

m1ga commented Apr 16, 2026

Hmmm... @Override public void onLowMemory(Activity activity) shouldn't work. onLowMemory is not in KrollProxy

@hansemannn
Copy link
Copy Markdown
Contributor

You are right, it was inferred from the others. Would be good to expose it on the SDK side, but no blocker here anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android: experimental BottomNavigation doesn't work with map

2 participants