Detecting elements boundaries on Alloy - titanium

My onClick event seems to not be firing, I have a button inside a <ScrollView>, and it does not give me any response, so I was wondering if there is a way to track which object was clicked so I could do the styling to make my buttons clickable again.
<Alloy>
<Window class="container">
<View class="insideContainer">
<View layout="horizontal">
<ImageView id="minLogo" image="/images/homeLogo.png" ></ImageView>
<ScrollableView id="mainViewInterna">
<View id="MainWelcomeText" class="MainWelcomeText rowLayout">
<Label class="welcomeText">BEM VINDO</Label>
<Label class="welcomeText">[ Usuário ]</Label>
<View class="button-row" width="200dp" height="200dp">
<Label id="logoutButton" class="button" onClick="logout">Log Out</Label>
</View>
</View>
</ScrollableView>
</View>
</View>
</Window>
</Alloy>
The Function:
function logout(){
Ti.API.log('it works');
}

var logout = function() {
$.logoutButton.removeEventListener('click',logout);
console.log('logout');
};
$.logoutButton.addEventListener('click',logout);

Related

Button width in react-native-paper

I am starting learning react-native-paper, i am not sure how to fix button width, currently it fills whole parent container.
<View>
<Button
icon="camera"
mode="contained"
onPress={() => console.log('Pressed')}
contentStyle={styles.btn}
>
Press me
</Button>
</View>
const styles = StyleSheet.create({
btn: {
width: 30
}
})
This is not working and button is still full width.
Need some help.
You can change the width of Button directly using style props and adding width to it.
<Button
icon="camera"
mode="contained"
onPress={() => console.log('Pressed')}
style={{ width: 100 }}
>
Press me
</Button>
If your View tag is a container for the button, the button needs its own View tag with the styles prop called there.
<View>
<View style={styles.btn}>
<Button
icon="camera"
mode="contained"
onPress={() => console.log('Pressed')}
>
Press me
</Button>
</View>
</View>
const styles = StyleSheet.create({
btn: {
width: 30
},
});

How to prevent this button from running When I use map in react native?

My code:
{this.state.News.slice(0, this.state.currentShow).map((item) => {
return (
<View>
<View>
<View>
<Text>{item.Title}</Text>
<Text>{item.Content}</Text>
</View>
<View>
<Image source={{uri: item.Image}} />
</View>
</View>
<View>
<Text>{item.creationTime}</Text>
<Button onPress={this.gotoNews(item.Id.toString())}>
<Text>Load More</Text>
</Button>
</View>
</View>
)
})}
Whenever this page is run, Everything is right But why the button onPress runs when the react native screen is loaded!!
Try to change your button handler call from a function call to a function
you can use ES6 arrow functions to do this :
<Button onPress={()=>this.gotoNews(item.Id.toString())}>
<Text>Load More</Text>
</Button>

How can i use NavigationBar shoutemui

I'm trying to use NavigationBar from the Shoutem UI toolkit.
My code:
<Screen>
<NavigationBar centerComponent={<Title>TITLE</Title>}/>
<ListView
data={groupedData}
renderRow={this.renderRow}
loading ={this.state.loading}
onRefresh={this.getAllNewsfeed.bind(this)}
onLoadMore ={this.loadMoreData.bind(this)}
loadMoreSpinner={<Spinner/>} />
<Button onPress={this.onLogout.bind(this)}>
<Text>
LOGOUT
</Text>
</Button>
</Screen>
But NavigationBar always hidden, listview above NavigationBar. But when I try replace it to Title. It still work. But I don't want use Title because I want add button back or something else same that.
This PR solves it https://github.com/shoutem/ui/pull/104/files but somehow we have removed it from the theme. We are going to fix that in next release but until then you can help yourself by this:
<Screen>
<NavigationBar
style={{
container: {
position: 'relative',
width: Dimensions.get('window').width,
}
}}
centerComponent={<Title>TITLE</Title>}
/>
<ListView
data={groupedData}
renderRow={this.renderRow}
loading ={this.state.loading}
onRefresh={this.getAllNewsfeed.bind(this)}
onLoadMore ={this.loadMoreData.bind(this)}
loadMoreSpinner={<Spinner/>}
/>
<Button onPress={this.onLogout.bind(this)}>
<Text>
LOGOUT
</Text>
</Button>
</Screen>
After release you will just have to change style prop to:
<NavigationBar
styleName="inline"
centerComponent={<Title>TITLE</Title>}
/>

In Alloy Titanuim, How to close widget's parent window

I have a widget that contain a back button, when click that back button i want to close the window that having the widget (parent window).
here is my widget.xml :
<Alloy>
<View id="topBar">
<View id="leftItems">
<ImageView id="backIcon" onClick="previousPage" />
<ImageView id="logo" />
</View>
<View id="midItems">
<Label id="pageTitle"></Label>
<ImageView id="searchIcon" onClick="searchIcon" platform="ios" />
<SearchBar id="searchBar" platform="ios" />
<SearchView id="searchView" ns="Ti.UI.Android" platform="android" onBlur="pageTitleVisiability" onFocus="pageTitleVisiability" />
</View>
<View id="rightItems">
<ImageView id="createIcon" onClick="createPost" />
</View>
</View>
</Alloy>
and in widget.js :
function previousPage(argument) {
// closing the window
}
i tried to send the custom property in the widget with the window name like this:
Alloy.createController('windowName').close();
but it says that the window is not opened
You can't create the controller in the widget and try to close it, you are creating a new instance of the window, not referencing the calling controller. I would use messaging to perform the close. Inside you previousPage function, add "$.trigger('closeParent');" to signal to close the window. Then inside the calling window (where the widget is referenced) add something like "$..on('closeParent', );" and then close the window in the function. I hope that makes sense.
Setting callbacks should solve your problem.
your "widget.js" :
var previousPageCallback;
function previousPage() {
if(previousPageCallback) previousPageCallback();
}
module.exports = {
previousPageCallback : previousPageCallback
};
your "previousWindow.xml"
<Window>
<Widget id="myWidget" src="<whateverYourWidgetNameIs>"/>
</Window>
your "previousWindow.js" (the window where you are using the widget)
$.myWidget.previousPageCallback = $.previousWindow.close();
Thanks n cheers

titanium alloy Widget not working

The widget that I have is working on other xml files..except for one...
The process goes like this...There's a view that when clicked, a window will open..
<Alloy>
<View class="vertical hsize">
<View class="hsize">
<Require src="actionbar" type="widget" />
</View>
<ScrollView class="container vertical whitebg">
<View class="downloadRowContainer horizontal">
<View class="downloadRow horizontal">
<View id="itemDl" onClick="viewItem" class="downloadItem graybg" />
<View class="divider" />
<View class="downloadItem graybg" />
</View>
</View>
<View class="downloadRowContainer horizontal">
<View class="downloadRow horizontal">
<View class="downloadItem graybg" />
<View class="divider" />
<View class="downloadItem graybg" />
</View>
</View>
</ScrollView>
</View>
</Alloy>
Here's the js:
function viewItem(e){
var showItem = Alloy.createController('viewdl').getView().open();
}
It works it opens viewdl.xml but the widget ain't working anymore on viewdl.xml alone.Any idea why?
Here's viewdl.xml(viewdl.js is blank):
<Alloy><Window class="vertical">
<View class="vertical hsize">
<View class="hsize"><Require src="actionbar" type="widget"/></View>
<ScrollView class="container vertical blackbg">
<View class="imgContainer"></View>
<View class="division"></View>
<Label>DOWNLOAD THIS WALLPAPER</Label>
</ScrollView>
</View></Window></Alloy>
Let me elaborate some points which I think are creating issues:
The root of the UI is Window or TabGroup or NavigationWindow/NavigationGroup : So these elements are responsible for opening and closing of the content/container in screen.
You can add some other View or its sub-element(Label,TableView,etc) to a window using add method.
IMO the widget should be added to the main container.
A simple example, let say we want 2 window application.
1st Window has a button which opens 2nd window.
2nd Window has 2 buttons
1st button close the current window.
2nd button loads some other view ( xml file ) to current window.
index.xml
<Alloy>
<Window id="first" layout="vertical" >
<Require src="actionbar" type="widget" />
<Button onClick="openWin2" title="Open" />
</Window>
</Alloy>
index.js
function openWin2() {
Alloy.createController('window2').getView().open({fullscreen:false});
}
window2.xml
<Alloy>
<Window id="second" layout="vertical" >
<Require src="actionbar" type="widget" />
<Button onClick="closeWin" title="Close" />
<Button onClick="loadData" title="Load Data" />
<View id="dynamicView" height="100px" width="100px"></View>
</Window>
</Alloy>
window2.js
function closeWin() {
$.second.close();
}
function loadData() {
$.dynamicView.add(Alloy.createController('dynamicData').getView());
}
dynamicData.xml
<Alloy>
<Label >Winter is coming !!</Label>
</Alloy>
Hope it is helpful.