0
votes

Is possible to have one xml for iOS and one xml for Android for the same controller?

For example:

I have que controller: UIPhoto.js

and I want to have 2 different xml and tss files: UIPhoto-iOS.xml and UIPhoto-Android.xml

and charge each when the device is iOS or Android.

Thank you.

3

3 Answers

4
votes

Yes it is possible and is quite simple! You just need to have a different folder for the specific platform you want to target. Imagine that you have the index.xml file inside Views folder, right? You can code your xml as you're used to and if you want a different file for Android (let's say), you just need to create a folder inside "Views" folder called Android. Check this image with a folder structure:

Alloy folder structure

Notice the Android folder in 'controllers' and the iOS in 'views' ;)

2
votes

You may use platform specific folder in your views

controllers   
--- UIPhoto.js
views
--- android
------ UIPhoto.xml
--- iOS
------ UIPhoto.xml

but i recommend you to use tss rather than use 2 xml and 2 tss.
for example in your tss:

"Window[platform=ios]":{
   fullscreen : true
}

"View[platform=android]" :{
   elevation : 8
}
"View[formFactor=tablet]" :{
   elevation : 8
}
"View[platform=android formFactor=handheld]" :{
   elevation : 8
}

and for your controller :

if(OS_IOS){
}
if(OS_ANDROID){
}
0
votes

I don't think you can switch xml file or tss file when device is iOS or Android.

But maybe this is helpful:

First of all you can detect OS with Ti.Platform.osname; in your index.js and valorize a global varibale like this Alloy.Globals.OS.

Now you can switch your code with a simple if statements also in js file with:

if(Alloy.Globals.OS == "android"){...}

In your tss file you can distingue platform like this:

"#title[platform=android]" : {
    font : { textStyle : Ti.UI.TEXT_STYLE_HEADLINE }
}