Skip to content

Commit

Permalink
Fixed a bug on Android where ensureRight and ensureBottom were not be…
Browse files Browse the repository at this point in the history
…ing honored.
  • Loading branch information
animecyc committed Jan 23, 2014
1 parent 82a095e commit 017a254
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion android/manifest
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 2.0.2
version: 2.0.3
apiversion: 2
description: Ti.Draggable
author: Seth Benjamin
Expand Down
41 changes: 37 additions & 4 deletions android/src/ti/draggable/DraggableGesture.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,21 @@ else if (yAxis)
double translationTop = lastTop - topEdge;

translateMappedProxies(translationLeft, translationTop);

Float ensureRightValue = null;
Float ensureBottomValue = null;

if (TiConvert.toBoolean(configProps, "ensureRight"))
{
ensureRightValue = (float) -leftEdge;
}

if (TiConvert.toBoolean(configProps, "ensureBottom"))
{
ensureBottomValue = (float) -topEdge;
}

this.setViewPosition(draggableProxy, viewToDrag, leftEdge, topEdge);
this.setViewPosition(draggableProxy, viewToDrag, (float) topEdge, (float) leftEdge, ensureBottomValue, ensureRightValue);

distanceX += Math.abs(lastLeft - leftEdge);
distanceY += Math.abs(lastTop - topEdge);
Expand Down Expand Up @@ -374,7 +387,7 @@ protected void prepareMappedProxies()

if (didModifyPosition)
{
this.setViewPosition(mappedProxy, mappedView, newLeft, newTop);
this.setViewPosition(mappedProxy, mappedView, (float) newTop, (float) newLeft, null, null);
}
}
}
Expand Down Expand Up @@ -417,24 +430,44 @@ protected void finalizeMappedTranslations()
TiViewProxy mappedProxy = (TiViewProxy) map.get("view");
View mappedView = mappedProxy.peekView().getOuterView();

this.setViewPosition(mappedProxy, mappedView, mappedView.getX(), mappedView.getY());
this.setViewPosition(mappedProxy, mappedView, mappedView.getY(), mappedView.getX(), null, null);
}
}
}

protected void setViewPosition(KrollProxy proxy, View view, double left, double top)
protected void setViewPosition(KrollProxy proxy, View view, Float top, Float left, Float bottom, Float right)
{
TiCompositeLayout.LayoutParams layout = (TiCompositeLayout.LayoutParams) view.getLayoutParams();

layout.optionLeft = new TiDimension(left, TiDimension.TYPE_LEFT);
layout.optionTop = new TiDimension(top, TiDimension.TYPE_TOP);

if (right != null)
{
layout.optionRight = new TiDimension(right, TiDimension.TYPE_RIGHT);
}

if (bottom != null)
{
layout.optionBottom = new TiDimension(bottom, TiDimension.TYPE_BOTTOM);
}

view.setLayoutParams(layout);
view.setTranslationX(0);
view.setTranslationY(0);

proxy.setProperty("left", left);
proxy.setProperty("top", top);

if (right != null)
{
proxy.setProperty("right", right);
}

if (bottom != null)
{
proxy.setProperty("bottom", bottom);
}
}

protected ConfigProxy getConfig()
Expand Down
2 changes: 1 addition & 1 deletion ios/manifest
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 2.0.2
version: 2.0.3
apiversion: 2
description: Ti.Draggable
author: Seth Benjamin
Expand Down

0 comments on commit 017a254

Please sign in to comment.