I have created a picker that shows list of countries and it works fine. Currently by default the first country is selected. I need to change it to another country. How should I do that?
This is the picker I created
Picker {
id: picker
title: "Select your country"
expanded:true
verticalAlignment: VerticalAlignment.Fill
// A DataModel is used to populate the picker.
dataModel: XmlDataModel {
source: "Model/CountryCodes.xml"
}
// Picker items are set up similarly as to how its done in a ListView.
pickerItemComponents: [
PickerItemComponent {
type: "country"
content: Container {
background: Color.create("#9B59B6")
layout: DockLayout {
}
Label {
multiline: true
maxWidth: 1000
text: pickerItemData.name
verticalAlignment: VerticalAlignment.Center
horizontalAlignment: HorizontalAlignment.Center
textStyle {
base:SystemDefaults.TextStyles.BodyText
color: Color.White
fontSize: FontSize.PointValue
fontSizeValue: 10.0
fontWeight: FontWeight.Normal
}
}
}
}
]
onSelectedValueChanged: {
// These are the currently selected indexes.
var index0 = picker.selectedIndex(0);
var type = dataModel.data([0, picker.selectedIndex(0)]);
console.log("Selected index:"+index0);
countryCode.mainText="+"+type.phoneCode;
}
}
My countrycodes.xml is in this format
<model>
<column loop="false" colspan="3" >
<country code='af' phoneCode='93' name='Afghanistan' />
<country code='al' phoneCode='355' name='Albania' />
........all other countries.....
</column>
</model>
Currently Afganistan shows selected all the time.
I used this, it loads which one from settings. This is placed in onCreationCompleted
picker.select(0, app.getValueFor("backImageID", 0));
and the second element is like this
picker.select(1, app.getValueFor("fontColorID", 0));
Related
# i am trying to add image to tab bar item but not able to load in react navigation #
## i am referring https://github.com/react-navigation/react-navigation/issues/1205#issuecomment-296708338 ##
import React from 'react';
import { Text, View, Image } from 'react-native';
import { createBottomTabNavigator, createAppContainer } from 'react-navigation'
import ScreenOne from './ScreenOne';
import Screentwo from './Screentwo';
import Preferences from './Preferences';
const TabNavigator = createBottomTabNavigator(
{
Home: {
screen : ScreenOne,
navigationOptions: {
showLabel: false,
tabBarIcon: <Image style={{ width: 30, height: 30 }} source={require('../images/Help_Header_Icon.png'
)}/>,
showIcon: true,
activeTintColor: '#00000',
inactiveTintColor: '#000000'
}
},
Settings: Screentwo,
Preference: Preferences
},
{
initialRouteName: "Home"
}
);
export default createAppContainer(TabNavigator);
### expecting to show image in tab bar item and hide tab bar label###
tabBarIcon
React Element or a function that given { focused: boolean,
horizontal: boolean, tintColor: string } returns a React.Node, to
display in the tab bar. horizontal is true when the device is in
landscape and false when portrait. The icon is re-rendered whenever
the device orientation changes.
Usage
{
defaultNavigationOptions: ({ navigation }) => ({
tabBarIcon: ({ focused, horizontal, tintColor, image }) => {
const { routeName } = navigation.state;
let imagepath;
if (routeName === "Home") {
imagepath = require('../images/Help_Header_Icon.png');
} else if (routeName === "Settings") {
imagepath = require('../images/Settings.png');
} else if (routeName === "Preference") {
imagepath = require('../images/Preference.png');
}
return (
<Image
style={{ width: 30, height: 30, resizeMode: "stretch" }}
source={imagepath}
/>
);
Please use Nativebase
https://docs.nativebase.io/Components.html#footer-tabs-icon-headref
import { Container, Header, Content, Footer, FooterTab, Button, Icon } from 'native-base';
<Footer>
<FooterTab>
<Button>
<Icon name="apps" />
</Button>
<Button>
<Icon name="camera" />
</Button>
<Button active>
<Icon active name="navigate" />
</Button>
<Button>
<Icon name="person" />
</Button>
</FooterTab>
</Footer>
I'm using react-navigation with StackNavigator. Is there a way to avoid the overlapping of the back button label and the headerTitle by truncating the back button label?
const MainNavigationOptions = {
headerStyle: {
backgroundColor: colors.CiPrimary
},
headerTitleStyle: {
color: 'white',
height: 50,
width: 140
},
headerTintColor: 'white',
headerTitle:
<Text>LONG TEXT FOR TESTING</Text>
}
Illustration of issue:
(This Answer takes into account that the viewer is using react-navigation 5.x)
In Your Screen component
export const screenOptions = (navData) => {
let title = navData.route.params.movieTitle;
if (title.length > 18) {
title = title.substr(0, 18) + "...";
}
return {
headerTitle: title,
};
};
Here, since we are using substr() , you can use it accordingly and truncate it to custom match your case, keeping in mind the edge cases.
Then you can import it in your AppNavigator.js or wherever you initialize your navigator (in my case below ;)
import {screenOptions as MoviesDetailScreenOptions} from
"../screens/MovieDetailScreen";
Here screenOptions is the named-export you are using MoviesDetailScreenOptions is the alias if i am not mistaken.
Create a style for your button label because it now left for you to style it your self and you can style it any way you want.
const styles = {
leftTouch: {
flexDirection: 'row',
...
},
customStyle: {
paddingLeft: 10,
...
}
textStyle: {
width: 60,
fontSize: 14,
......
}
}
const { leftTouch, customStyle, textStyle} = styles;
Instead of Icon you can use <Image /> but am assuming you are using an icon i.e react-native-vector-icon or likes.
N.B Now you have control of everything the button should do especially when pressed.
const MainNavigationOptions = {
headerStyle: {
backgroundColor: colors.CiPrimary
},
headerTitleStyle: {
color: 'white',
height: 50,
width: 140
},
.....
headerLeft: ( <TouchableOpacity style={leftTouch} onPress={() => goBack()} >
<Icon name="ios-arrow-dropleft-circle-outline" size={25} style={customStyle} color="#ffffff" />
<Text numberOfLines={1} style={textStyle}>A Longer Text for testing</Text>
</TouchableOpacity>
)
}
If you mean to shorten the back button label, why not use either:
headerBackTitle (change the Back label for the previous screen, put it in navigationOptions of the previous screen);
headerBackTitleStyle (change the Back label displayed on current screen, put it in navigationOptions of the current screen)
I want to make a gender selection using picker. but the mode is not working in ios. Im not sure in android.
<Picker
style={{justifyContent: 'center',backgroundColor: 'white'}}
selectedValue={this.state.gender}
onValueChange={(gender) => this.setState({ gender })}
mode='dialog'
>
<Item label="Male" value="Male" />
<Item label="Female" value="Female" />
</Picker>
Hope anyone could give some suggestion..
Thank you
The <Picker> component renders as a UIPickerView on iOS - that's what you're seeing there. This picker is rendered in-place rather than in a modal (as is the case on Android) - the mode prop you specified only applies to Android.
There are two options: render the picker within something like a <Modal> or use a different component entirely.
I solved this type of issue by doing like this.
import PickerExample from './PickerExample.js';
class Sample extends React.Component {
constructor(props) {
super(props);
this.state = {gender: '',};
this.updateGender = this.updateGender.bind(this);
}
updateGender(val){
this.setState({
gender: val
},function(){
alert("callback function as your wish")
});
}
render(){
return (
<PickerExample gender={this.state.gender} updateGender={this.updateGender.bind(this)} />
);
}
The PickerExample.js file look like this.
export default PickerExample = (props) => {
return (
<Picker selectedValue = {props.gender} onValueChange = {props.updateGender}>
<Picker.Item label = "MALE" value ="Male" />
<Picker.Item label = "Female" value = "female" />
</Picker>
);
}
I use the .ios.jsx extension for the iOS specific picker. Which I code as follows:
export const SelectWidget = ({
selectedOption,
setSelectedOption,
placeholderLabel,
options
}) => {
const items = options.map((option) => {
return <Picker.Item
key={option.key ?? option.label}
label={option.label}
value={option.value}
/>;
});
return (
<Picker
onValueChange={(value) => {
setSelectedOption(value);
}}
placeholder={{
label: placeholderLabel,
value: null,
}}
selectedValue={selectedOption}
style={{
width: '100%', // fill up the width of the device (without this, nothing gets displayed
}}
itemStyle={{
height: 150, // this reduces the height of the selector
color: colors.text, // if you're in dark mode set this to white.
}}
>
// default item
<Picker.Item label={placeholderLabel} value={null} />
{items}
</Picker>
);
};
I am developing my first application with Titanium Alloy. For iOS i use the native iOS trash button, using systemButton="TRASH". For that button i also have an onClick handler, onClick="deleteReckon". However, the deleteReckon method is not called upon clicking the trash button.
This is the "reckonDetails.xml" view for iOS (hence, included in an "ios" directory in the "views" directory) :
<Alloy>
<Window class="container">
<!-- Make a toolbar for delete and info buttons -->
<Toolbar platform="ios" bottom="0" borderTop="true" borderBottom="false">
<!-- The Items tag sets the Toolbar.items property. -->
<Items>
<Button id="info" systemButton="INFO_LIGHT" />
<FlexSpace/>
<Button id="del" onClick="deleteReckon" systemButton="TRASH" />
</Items>
</Toolbar>
<!-- We will display all reckon detail, date, total, ... -->
<View layout='vertical'>
<Label id="dateLabel"></Label>
<!-- ... OTHER LABELS ... -->
</View>
</Window>
</Alloy>
And this is the "reckonDetails.js" controller :
var args = arguments[0] || {};
// Fill in all labels of this view
$.dateLabel.text = "Date: " + args.date || 'Unknown Date';
// ...
function deleteReckon() {
console.log("deleteReckon called"); // Is never displayed
// Delete the selected reckon (this element of the collection)
var selectedReckon = args.selected_reckon;
selectedReckon.destroy();
// Go back to the index page
var args = {};
var indexView = Alloy.createController("index", args).getView();
indexView.open();
}
I put a console.log(...); statement in it to check if the function is called, but it is not..
And finally this is my "reckonDetails.tss" style (not sure if this is relevant for the problem?) :
".container[platform=ios]" : {
backgroundColor: 'white'
},
"Label": {
font: {
fontSize: '20'
},
left: '10'
},
"#dateLabel": {
font: {
fontSize: '30'
},
left: '10'
}
I've tested iOS system TRASH button on Titanium Alloy and Classic project and it's working just fine for me. Please have a look on my code below,
var win = Ti.UI.createWindow({
title : 'Window',
backgroundColor: '#white'
});
var trash = Titanium.UI.createButton({
systemButton: Titanium.UI.iPhone.SystemButton.TRASH,
});
flexSpace = Titanium.UI.createButton({
systemButton:Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE
});
var toolbar = Titanium.UI.iOS.createToolbar({
items:[trash, flexSpace],
bottom:0,
borderTop:true,
borderBottom:false
});
win.add(toolbar);
trash.addEventListener('click', function(){
console.log("Treash called");
});
win.open();
Hope you can now find what you are looking for. For more details, please check the documentation from here at http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.iOS.SystemButton-property-TRASH and http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.iOS.Toolbar.
Thanks
I need to develop a bb 10 cascades app in which i need to add a control like in this image
http://subefotos.com/ver/?37868d57047746ce1ea9ca55b7637e9eo.jpg#codigos
(rounded in red color)
when i touch on second bubble, i need to show second screen ,for third bubble third screen and so on. Default screen should be displayed is first screen(first bubble high lights)
but how to do it in BB 10 cascades and what is that control called in bb 10?
Please help,
Thanks !!!
-------AM ADDED PAGE NAVIGATION HERE, REUSE THIS CODE FOR YOUR PROJECT-------------
Get sample app from my github samples for your query....
https://github.com/svmrajesh/BB-10-Cascades/tree/master/MY%20APPS/stackNavigation
1.main.qml: (first page)
import bb.cascades 1.0
NavigationPane { id: navigationPane backButtonsVisible: false peekEnabled: false
Page {
id: rootPage
Container {
background: Color.LightGray
layout: DockLayout {
}
Label {
text: "First page"
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
}
}
actions: [
ActionItem {
title: "Next page"
ActionBar.placement: ActionBarPlacement.OnBar
onTriggered: {
var page = pageDefinition.createObject();
navigationPane.push(page);
}
attachedObjects: ComponentDefinition {
id: pageDefinition
source: "PageTwo.qml"
}
}
]
}
onPopTransitionEnded: {
page.destroy();
}
}
2.second page
import bb.cascades 1.0
Page { id: pageTwo Container { background: Color.Gray layout: DockLayout {
}
Label {
text: "Second page"
horizontalAlignment: HorizontalAlignment.Center
}
Container {
layout: StackLayout {
}
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
Button {
text: qsTr("Next Page")
imageSource: "asset:///images/picture1thumb.png"
onClicked: {
// show detail page when the button is clicked
var page = getSecondPage();
console.debug("pushing detail " + page)
navigationPane.push(page);
}
property Page secondPage
function getSecondPage() {
if (! secondPage) {
secondPage = secondPageDefinition.createObject();
}
return secondPage;
}
attachedObjects: [
ComponentDefinition {
id: secondPageDefinition
source: "PageTwoOne.qml"
}
]
}
Button {
text: "Previous Page"
onClicked: {
navigationPane.pop();
}
}
}
}
/* ------------- Use this Code If back button visibility is "True"-----------------
paneProperties: NavigationPaneProperties {
backButton: ActionItem {
title: "Back"
// imageSource: "asset:///back.png"
onTriggered: {
navigationPane.pop();
}
}
} */
}
3.last page
import bb.cascades 1.0
Page { id: pageTwoone
Container {
background: Color.DarkGray
layout: DockLayout {}
Label {
horizontalAlignment: HorizontalAlignment.Center
text: "Last Page"
}
Container {
layout: StackLayout {}
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
Button {
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
text: qsTr("Goto Home Page")
onClicked: {
// show detail page when the button is clicked
navigationPane.navigateTo(rootPage);
}
}
Button {
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
text: qsTr("Goto Back")
onClicked: {
// show detail page when the button is clicked
navigationPane.pop();
}
}
}
}
}
------------ ADD More pages to navigate using this code----------------------------
-------------copy this code and run.. get sample app from above link if needed ------