Skip to content

Commit

Permalink
[Android] Added imperative #snapToPoint that accepts {x:0, y:0}
Browse files Browse the repository at this point in the history
  • Loading branch information
woodpav committed Oct 25, 2018
1 parent 941a263 commit 6b17ea3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,13 @@ public void snapTo(int index) {
}
}

public void snapToPoint(InteractablePoint snapPoint) {
this.animator.removeTempBehaviors();
this.dragBehavior = null;
addTempSnapToPointBehavior(snapPoint);
addTempBounceBehaviorWithBoundaries(this.boundaries);
}

public void changePosition(PointF position) {
if(dragBehavior != null) return;
setTranslationX(position.x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ public class InteractableViewManager extends ViewGroupManager<InteractableView>
public static final String REACT_CLASS = "InteractableView";
public static final int COMMAND_SET_VELOCITY = 1;
public static final int COMMAND_SNAP_TO = 2;
public static final int COMMAND_CHANGE_POSITION = 3;
public static final int COMMAND_BRING_TO_FRONT = 4;
public static final int COMMAND_SNAP_TO_POINT = 3;
public static final int COMMAND_CHANGE_POSITION = 4;
public static final int COMMAND_BRING_TO_FRONT = 5;


@Override
Expand All @@ -39,6 +40,7 @@ public Map<String,Integer> getCommandsMap() {
return MapBuilder.of(
"setVelocity", COMMAND_SET_VELOCITY,
"snapTo", COMMAND_SNAP_TO,
"snapToPoint", COMMAND_SNAP_TO_POINT,
"changePosition", COMMAND_CHANGE_POSITION,
"bringToFront", COMMAND_BRING_TO_FRONT
);
Expand All @@ -61,6 +63,10 @@ public void receiveCommand(
view.snapTo(snapPoint);
return;
}
case COMMAND_SNAP_TO_POINT: {
view.snapToPoint(RNConvert.interactablePoint(args.getMap(0)));
return;
}
case COMMAND_CHANGE_POSITION: {
view.changePosition(RNConvert.pointF(args.getMap(0)));
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/InteractableView.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class WrappedAnimatedInteractableView extends Component {
} else if (Platform.OS === 'android') {
UIManager.dispatchViewManagerCommand(
ReactNative.findNodeHandle(this),
UIManager.InteractableView.Commands.changePosition,
UIManager.InteractableView.Commands.snapToPoint,
[snapPoint],
);
}
Expand Down

0 comments on commit 6b17ea3

Please sign in to comment.