Added navigation button doesn't work first time in Titanium alloy - iphone

i added navbutton to navigation and i wrote 'click' function on to it doesn't work first time . actually am adding button to navigation bar on that first click it was not working on second click it works how can i solve this
my xml code is
<Alloy>
<Window id="aboutWin" name="aboutWinName">
<NavigationGroup id="navAbout" platform="ios">
<Window class="container" id="aboutChildWin">
<View id="aboutView">
<ImageView id="logoImg"></ImageView>
<ImageView id='logoWrd'></ImageView>
<Label id="versionLbl"></Label>
</View>
<View id="footView"></View>
</Window>
</NavigationGroup>
</Window>
</Alloy>
and my Js code is
var button = Titanium.UI.createButton({
// title:"Back",
backgroundImage:"/images/MenuList.png",
// top : 4.5,
height : 35,
width : 40,
// left : 4
})
$.aboutChildWin.leftNavButton = button;
button.addEventListener('click',function(){
if(Ti.App.currentAnimateWindow == "About")
{
Ti.App.socialWindow.hide();
Ti.App.menuWindow.show();
$.aboutWin.animate(animateLeft);
Ti.App.currentAnimateWindow = "Menu";
}
else if(Ti.App.currentAnimateWindow == "Menu")
{
$.aboutWin.animate(animateRight);
Ti.App.currentAnimateWindow = "About";
}
})
can any one solve this

i just make small change, insert of adding button to navigation window i add the navbutton to whole window.
code is :
$.aboutWin.leftNavButton = button;

That might sound stupid but did you try to change the order?
var button = Titanium.UI.createButton({
// title:"Back",
backgroundImage:"/images/MenuList.png",
// top : 4.5,
height : 35,
width : 40,
// left : 4
});
button.addEventListener('click',function(){
if(Ti.App.currentAnimateWindow == "About")
{
Ti.App.socialWindow.hide();
Ti.App.menuWindow.show();
$.aboutWin.animate(animateLeft);
Ti.App.currentAnimateWindow = "Menu";
}
else if(Ti.App.currentAnimateWindow == "Menu")
{
$.aboutWin.animate(animateRight);
Ti.App.currentAnimateWindow = "About";
}
};
$.aboutChildWin.leftNavButton = button;
Without using alloy this change makes no difference.

Related

Infinite loop and dynamic content on slides [duplicate]

Hi I'm using ngFor to create an set of 3 slides while starting in the middle so I'm guaranteed to be able to slide to left or right on start.
When I slide right I can simple listen to the reachedEnd and push another slide to the array i'm looping.
but I have a problem with adding a slide to the beginning. If I do the same as above and use e.g. array.unshift() or spread to add an item to the beginning, the view think it's on position 0 and snaps the view to the new slide.
The code below would work but it animates the slide change back to index 1.
slide = [0,1,2] //example to loop
slideChanged(event) {
if(this.slides.isBeginning()){
this.slide = [this.slide[0]-1, ...this.slide];
this.slides.update();
this.slides.slideTo(1)
}
}
<ion-slides [initialSlide]="1" (ionSlideDidChange)="slideChanged($event)">
<ion-slide *ngFor="let item of slide">
<h1>Slide {{item}}</h1>
</ion-slide>
</ion-slides>
Any help is appreciated!
You can do that by using the ionSlideNextEnd and ionSlidePrevEnd events from the Slides. Please take a look at this working plunker
The view
<ion-header>
<ion-navbar>
<ion-title>Dynamic slides Demo</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<ion-slides #slider (ionSlideNextEnd)="loadNext()" (ionSlidePrevEnd)="loadPrev()" [initialSlide]="1">
<ion-slide *ngFor="let n of numbers">
<h2>Current slide: {{n}}</h2>
</ion-slide>
</ion-slides>
</ion-content>
The component
#Component({...})
export class HomePage {
#ViewChild('slider') private slider: Slides;
numbers = [0,1,2];
firstLoad = true;
constructor() {}
loadPrev() {
console.log('Prev');
let newIndex = this.slider.getActiveIndex();
newIndex++;
this.numbers.unshift(this.numbers[0] - 1);
this.numbers.pop();
// Workaround to make it work: breaks the animation
this.slider.slideTo(newIndex, 0, false);
console.log(`New status: ${this.numbers}`);
}
loadNext() {
if(this.firstLoad) {
// Since the initial slide is 1, prevent the first
// movement to modify the slides
this.firstLoad = false;
return;
}
console.log('Next');
let newIndex = this.slider.getActiveIndex();
newIndex--;
this.numbers.push(this.numbers[this.numbers.length - 1] + 1);
this.numbers.shift();
// Workaround to make it work: breaks the animation
this.slider.slideTo(newIndex, 0, false);
console.log(`New status: ${this.numbers}`);
}
}
For you who wonder why this not works on Ionic 4, just add little bit changes on typescript component
This code below works on IONIC 4 :
ionSlideNextEnd(){
if(this.firstLoad) {
// Since the initial slide is 1, prevent the first
// movement to modify the slides
this.firstLoad = false;
return;
}
console.log('Next');
this.daySlider.getActiveIndex().then(idx=>{
let newIndex=idx
console.log(newIndex)
newIndex--;
this.numbers.push(this.numbers[this.numbers.length - 1] + 1);
this.numbers.shift();
// Workaround to make it work: breaks the animation
this.daySlider.slideTo(newIndex, 0, false);
console.log(`New status: ${this.numbers}`);
});
}
ionSlidePrevEnd(){
console.log('Prev');
this.daySlider.getActiveIndex().then(idx=>{
let newIndex=idx
console.log(newIndex)
newIndex++;
this.numbers.unshift(this.numbers[0] - 1);
this.numbers.pop();
// Workaround to make it work: breaks the animation
this.daySlider.slideTo(newIndex, 0, false);
console.log(`New status: ${this.numbers}`);
});
}
Or Much more simpler you can remove getter for Active Index, use below code for Ionic 4:
ionSlideNextEnd(){
if(this.firstLoad) {
this.firstLoad = false;
return;
}else{
this.numbers.push(this.numbers[this.numbers.length - 1] + 1);
this.numbers.shift();
// Workaround to make it work: breaks the animation
this.daySlider.slideTo(1,0,false);
this.monthViewData.selectedTime=new Date(this.monthViewData.selectedTime.setDate(this.monthViewData.selectedTime.getDate()+1));
this.eventSource = this.tmp_events.filter((item)=>{
if(item.startTime >= this.monthViewData.selectedTime.setHours(0,0,0,0) && item.endTime < this.monthViewData.selectedTime.getTime()){
return item;
}
});
}
}
ionSlidePrevEnd(){
this.numbers.unshift(this.numbers[0] - 1);
this.numbers.pop();
this.daySlider.slideTo(1,0,false);
this.monthViewData.selectedTime=new Date(this.monthViewData.selectedTime.setDate(this.monthViewData.selectedTime.getDate()-1));
this.eventSource = this.tmp_events.filter((item)=>{
if(item.startTime >= this.monthViewData.selectedTime.setHours(0,0,0,0) && item.endTime <= this.monthViewData.selectedTime.getTime()){
return item;
}
});
}

Not able to toggle ui5 button

new sap.m.Button("manualimage",{
icon : 'resources/Green.JPG',
width : "40px",
height : "40px",
press :function(e) {
var myBtn = sap.ui.getCore().byId("manualimage");
console.log(document.getElementById("manualimage").icon);
myBtn.setIcon('');
}
})
When I click on the button the Icon is not changing, any suggestions what I might be doing wrong here?
Below is my code which is working ( on UI5 version 1.42).
I only find one mistake : You should use ToggleButton to keep the state of Button. Say remove image if pressed or set image back when pressed back ( ie. not pressed).
Code in XML :
<ToggleButton icon='./images/ICICI.png' text ='hey' pressed='false' press='handlePress' />
Code in Controller:
handlePress: function(evt) {
var oSource = evt.getSource()
var bPressed = oSource.getPressed();
if(bPressed) {
oSource.setIcon('');
} else {
oSource.setIcon('./images/ICICI.png');
}
}
Let me know if this works for you.
When you use:
var myBtn = sap.ui.getCore().byId("manualimage");
your var myBtn is undefined, because using sap.ui.getCore() id of button is expecting something like:
sap.ui.getCore().byId("__xmlview1--manualimage");
where __xmlview1-- is autogenerated by framework. So please use this code instead:
var myBtn = this.byId("manualimage");

(Ionic 2) Keep auto play in slides when the slide is swiped

i have the slider like this:
<ion-slides #promoSlider [options]="homeOptions" (change)="onPromoSlideChanged()" >
<ion-slide *ngFor="let promo of promos">
<img *ngIf="promo" src="{{promo.image}}" style="width:300px;height:300px;margin:auto;display:block" >
</ion-slide>
</ion-slides>
I have use this options to keep my slide playing using auto play:
homeOptions = {
initialSlide: 0,
loop: true,
autoplay:2000
};
But the problem is when i swipe the slider the auto play is stopped and the slider is not sliding again. How to keep the slider playing even i swipe the slider. I have try this code:
onPromoSlideChanged() {
alert('ABC');
this.promoSlider.options = this.homeOptions;
this.promoSlider.rapidUpdate();
//What should i do in this method?
};
What event i need to keep the slider slide again (keep playing) when i swipe the slider ? Thanks...
You can find your answer here => https://forum.ionicframework.com/t/how-to-keep-slides-auto-play-when-the-slides-is-swiped/54025/6
The official docs reference the component Swiper as the base of the ion-slides component, so the API should be the same as the one described in http://idangero.us/swiper/api/11.
You could use the option autoplayDisableOnInteraction to avoid disabling auto play after the user interaction.
Your options array should be:
homeOptions = {
initialSlide: 0,
loop: true,
autoplay:2000,
autoplayDisableOnInteraction: false
};
Hope it helps.
$scope.images = {"status":true,"msg":"2 record(s) found","sliders":[{"title":"slider 1","content":"test
value","weblink":null,"image":"http:\/\/192.168.8.54\/test\/media\/mbimages\/a\/m\/test.jpg"},{"title":"Slider
2","content":null,"weblink":null,"image":"http:\/\/192.168.8.54\/test\/media\/mbimages\/
a\/m\/test.png"}]}
<ion-slide-box delegate-handle="img-viewer" options="options" does-continue="true" loop="true" auto-play="true" slide-interval="5000" >
<ion-slide ng-repeat="nt in images" ng-if="nt.slider_position == '1'" >
<div class="box"><img ng-src="{{nt.image}}" style="width:400px;height:200px;margin:auto;display:block"/></div>
</ion-slide>
</ion-slide-box>
**Controller**
$scope.counter = 0;
$interval(function ()
{
if($scope.counter == $ionicSlideBoxDelegate.$getByHandle('img-viewer').currentIndex() + 1)
{
$ionicSlideBoxDelegate.$getByHandle('img-viewer').slide(0);
}
else{
$ionicSlideBoxDelegate.$getByHandle('img-viewer').update();
}
}, 2000);
angular.forEach($scope.images, function(value, key){
if(value.slider_position == "1")
{
$scope.counter++;
}
Using Observable works for your scenario. You can use it as -
import {Observable} from 'Rxjs/rx';
// in class -
#ViewChild(Slides) slides: Slides;
ionViewDidEnter() {
//you get slider data from any web service
this.sliderObservable = Observable.interval(3000).subscribe(x => {
this.autoPlaySlider();
// or you can do this, it will start autoplay at every 3 seconds
// this.slides.startAutoplay();
});
}
autoPlaySlider(){
var slider_index = this.slides.getActiveIndex();
if(slider_index < this.sliderData.length){
this.slides.slideTo(slider_index+1);
}
else{
this.slides.slideTo(0);
}
}
ionViewDidLeave(){
this.sliderObservable.unsubscribe();
}
You can find more reference Here

How to bind popup user control to view model and how to handle back button? (Windows Phone 8.1 Runtime)

I'm working on WP 8.1 runtime application and I'm using Caliburn.Micro. Application follows MVVM pattern. I have an ItemPageView and ItemPageViewModel and data binding works as it should.
I want to add popup (UserControl) over ItemPageView(Page) after I click one item on ItemPage. Popup has only one ScrollViewer containg one Image and I want to do something like this :
<Image x:Name="imageFull"
Source="{Binding _currentItem.ImageURL}"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
_currentItem is a property of ItemPageViewModel.
My second problem is related to Back button. I've added this to my code:
void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
{
Frame frame = Window.Current.Content as Frame;
if (_popUpActive)
{
_popUpActive = false;
_showImagePopUp.Close();
frame.GoForward();
//var lastPage = frame.BackStack.LastOrDefault();
//frame.Navigate(typeof(SingleGuideView));
e.Handled = true;
}
else
{
frame.GoBack();
e.Handled = true;
}
}
After I click on Back button Popup will close, and after that, it will navigate back. Only "solution" to stay on current view is to call frame.GoForward(); .
About the Popup, you can write some Code like the following in you XAML (Keep the Popup in just below the First Grid):
<!-- This is the First Grid -->
<Grid>
<Popup x:Name="myPopup" Width="400">
<ScrollViewer>
<StackPanel>
<Image x:Name="imageFull"
Source="{Binding _currentItem.ImageURL}"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</StackPanel>
</ScrollViewer>
</Popup>
</Grid>
You can handle the problem with the Popup by having a Counter for the Hardware Back Button Press. Have a look at the Code Below:
int _popUpCounter = 0, _dummyCounter = 0;
void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
{
_dummyCounter++;
Frame frame = Window.Current.Content as Frame;
if (_popUpCounter == 0 && _dummyCounter == 1)
{
_popUpCounter = 1;
_popUpActive = false;
_showImagePopUp.Close();
frame.GoForward();
//var lastPage = frame.BackStack.LastOrDefault();
//frame.Navigate(typeof(SingleGuideView));
e.Handled = true;
}
else if (_popUpCounter == 1 && _dummyCounter == 2)
{
_popUpCounter = _dummyCounter = 0;
frame.GoBack();
e.Handled = true;
}
}
This will help you with the problem related to Popup.

Accessing the first image when the second image of a two image div is hover or clicked

I have a div containing two images which is wrapped with a hover event. These images are left and right arrows. When I hover on the right arrow, I need to change the opacity on the left arrow. The html code is:
<div class="arrows">
<img src="left-arrow.jpg" id="left" />
<img src="right-arrow.jpg" id="right" />
</div>
jquery code
$('.arrows img').hover(function() {
var imgId = $(this).attr('id');
if (imgId == "right") {
// change opacity on left arrow
$(this).parent().img.eq(0).css({"opacity" : .5}); // does not work
$('arrows img.eq(0)').css({"opacity" : .5}); // does not work
}
});
Any suggestion that I can try.
Try this:
$('.arrows img').hover(function() {
$(this).siblings().css({"opacity" : .5});
});
Edit:
If you are looking to gray out the left or right arrow based on first or last page do this:
On Hover:
$('.arrows img').hover(function() {
$(this).css({"opacity" : .5});
});
On Click:
$('.arrows img').click(function() {
$(this).css({"opacity" : .5});
});