The same base of titanium codes for Android and Iphone

I am trying to create a single code base for Iphone and Android for a mid-level application. (4 tabs, several windows, cards, etc.) Using the itanium 2.1 API. However, I found that things on the Android platform do not work as smoothly or willingly as on the Iphone epsecially tableviews and UI elemnts. The responsiveness of the user interface on Android is also sluggish. Examples of kitchen sinks are quite simple. I am looking at a ready-to-use application that should be supported in at least a couple of years. Has anyone worked on similar lines with platform quirks and achieved success in creating fully functional iOS and Android applications from SAME codebase?

+4
source share
2 answers

Titanium is not intended for 1 code base for everyone. You need to rewrite the material for each OS. However, some application developers claim to have reused 95% of their code. Thus, only 5% of the code is OS dependent. But I'm sure their code is filled with if-elses.

What I recommend doing in order to be able to support it properly, without thousands of if-else constructs, creates a single base core and writes code specifically for user interface issues for each OS. So you have the code associated with the UI for Android, the UI code for iOS and 1 core working for both.

Since Android and iOS are very different from each other, recording the same code base will ensure that you can never use OS-specific functions (for example, the Android hardware menu button or iOS NavigationGroup) and make the user interface look unintuitive.

+3
source

I have great success using the CommonJS engine to compile, to represent the root view, which then has os-specific features.

For example, my os-independent view might be ui / MyView.js :

var createAddButton = require("ui/MyView.AddButton"); var MyView = function() { var self = Ti.UI.createWindow(); createAddButton(self, function() { alert('ADD!'); }); return self; }; module.exports = MyView; 

Then I create os-specific functions to handle it:

iphone / / MyView.AddButton.js

 module.exports = function(view, addHandler) { var addButton = Titanium.UI.createButton({ systemButton: Titanium.UI.iPhone.SystemButton.ADD }); addButton.addEventListener("click", addHandler); view.rightNavButton = addButton; }; 

Android / u / MyView.AddButton.js

 module.exports = function(view, addHandler) { view.activity.onCreateOptionsMenu = function(e){ var menuItem = e.menu.add({ title: "Add" }); menuItem.addEventListener("click", addHandler); }; }; 

The CommonJS system that they implemented will select the appropriate version of MyView.AddButton.js so that the button is added to the desired location. This allows most views to be the same, but os-specific things should be separated properly.

+4
source

Source: https://habr.com/ru/post/1435898/


All Articles