Skip to content

Instantly share code, notes, and snippets.

@rborn
Forked from bender-rulez/shortExample
Last active August 29, 2015 14:18
Show Gist options
  • Save rborn/c8ce024d86a67d4ba2ad to your computer and use it in GitHub Desktop.
Save rborn/c8ce024d86a67d4ba2ad to your computer and use it in GitHub Desktop.
var fadeIntro = Titanium.UI.createAnimation();
fadeIntro.opacity = 1.0;
fadeIntro.duration = 250;
var fadeOutro = Titanium.UI.createAnimation();
fadeOutro.opacity = 0.0;
fadeOutro.duration = 250;
var fadeOutSlow = Titanium.UI.createAnimation();
fadeOutSlow.opacity = 0.0;
fadeOutSlow.duration = 550;
var fadein = Titanium.UI.createAnimation();
fadein.opacity = 1.0;
fadein.duration = 150;
// image that calls this function onclick event has 'orgImg' and 'image' urls as params
function showImages(e) {
var localPoint = {x:e.x,y:e.y};
var globalPoint = this.convertPointToView(localPoint,self);
// https://github.com/adrianopaladini/Live-blurView
var blur = require('com.apaladini.blur');
var blurViewDark = blur.createView({
top:0,
height:Ti.UI.FILL,
width:Ti.UI.FILL,
style:0
});
var imageWin = Ti.UI.createWindow({
backgroundColor:'black',
statusBarStyle:Ti.UI.iPhone.StatusBar.LIGHT_CONTENT,
fullscreen:true,
opacity: 0.0,
});
var imageFull = Ti.UI.createImageView({
width:'100%',
image: this.orgImg ? this.orgImg : this.image,
});
var backButton = Ti.UI.createButton({
right:10,
top:10,
width: 90,
height: Ti.UI.SIZE,
font:{fontSize:14,fontWeight:'normal'},
color:'white',
textAlign:'center',
title:L('close'),
borderWidth:1,
borderColor:'#fff',
borderRadius:4,
_parent:imageWin,
});
backButton.addEventListener('click', function(e){
this._parent.close();
});
var imageScroll = Ti.UI.createScrollView({
width:Ti.UI.SIZE,
height:Ti.UI.FILL,
contentHeight:Ti.UI.SIZE,
contentWidth:Ti.UI.SIZE,
maxZoomScale:2, minZoomScale:1, zoomScale:1,
initZoomScale:0.75,
disableBounce: false,
verticalBounce:true,
});
imageScroll.add(imageFull);
var dragEnded = false;
imageScroll.addEventListener("dragEnd",function(e) {
if (e.source.currentZoomScale == e.source.minZoomScale) {
if (e.source.contentOffset.y < -100) {
dragEnded = true;
backButton.hide();
e.source.setContentOffset({x:0 ,y:-(e.source.rect.height)},{animated:true});
blurViewDark.animate(fadeOutSlow,function(){
setTimeout(function(){
imageWin.close();
},150);
});
}
if (e.source.contentOffset.y > 100) {
dragEnded = true;
backButton.hide();
e.source.setContentOffset({x:0 ,y:e.source.rect.height},{animated:true});
blurViewDark.animate(fadeOutSlow,function(){
setTimeout(function(){
imageWin.close();
},150);
});
}
}
});
imageScroll.addEventListener("dragStart",function(e) {
});
var lastY = 0;
var alphaValue = 1.0;
var buttonFade = false;
imageScroll.addEventListener("scroll",function(e) {
e.source.currentZoomScale = e.curZoomScale;
if (e.curZoomScale == e.source.minZoomScale && (e.dragging == true || e.decelerating == true)) {
if (e.y > lastY && (e.y > 0)) {
if (alphaValue > 0) {
alphaValue = alphaValue - parseFloat(0.01);
backButton.opacity = 0.0;
}
lastY = e.y;
}
else if(e.y > lastY && (e.y < 0)) {
if (alphaValue > 0) {
alphaValue = alphaValue + parseFloat(0.01);
}
lastY = e.y;
}
else if (e.y < lastY && (e.y < 0)) {
if (alphaValue > 0) {
alphaValue = alphaValue - parseFloat(0.0075);
backButton.opacity = 0.0;
}
lastY = e.y;
}
else if(e.y < lastY && (e.y > 0)) {
if (alphaValue > 0) {
alphaValue = alphaValue + parseFloat(0.0075);
}
lastY = e.y;
}
else {
alphaValue = 1.0;
}
if (e.decelerating == true && e.dragging == false && buttonFade == false){
buttonFade = true;
backButton.animate(fadein,function(){
buttonFade = false;
});
}
imageWin.backgroundColor = 'rgba(0,0,0,'+alphaValue.toFixed(2)+')';
}
else {
if (dragEnded == true){
imageWin.backgroundColor = 'rgba(0,0,0,0.0)';
}
else {
imageWin.backgroundColor = 'rgba(0,0,0,1.0)';
if (backButton.opacity == 0.0) {
buttonFade = true;
backButton.animate(fadein,function(){
buttonFade = false;
});
}
}
}
});
blurViewDark.add(imageScroll);
blurViewDark.add(backButton);
imageWin.add(blurViewDark);
var currentScale, oldScale = 1;
imageWin.open();
imageWin.animate(fadeIntro,function(){
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment