Skip to content

Commit a1c7618

Browse files
committed
Fix logic for costraint settings for android pan handler.
1 parent fd9efed commit a1c7618

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,14 @@ public PanGestureHandler create() {
196196
@Override
197197
public void configure(PanGestureHandler handler, ReadableMap config) {
198198
super.configure(handler, config);
199+
boolean hasCustomActivationCriteria = false;
199200
if (config.hasKey(KEY_PAN_MIN_DELTA_X)) {
200201
handler.setMinDx(PixelUtil.toPixelFromDIP(config.getDouble(KEY_PAN_MIN_DELTA_X)));
202+
hasCustomActivationCriteria = true;
201203
}
202204
if (config.hasKey(KEY_PAN_MIN_DELTA_Y)) {
203205
handler.setMinDy(PixelUtil.toPixelFromDIP(config.getDouble(KEY_PAN_MIN_DELTA_Y)));
206+
hasCustomActivationCriteria = true;
204207
}
205208
if (config.hasKey(KEY_PAN_MAX_DELTA_X)) {
206209
handler.setMaxDx(PixelUtil.toPixelFromDIP(config.getDouble(KEY_PAN_MAX_DELTA_X)));
@@ -210,24 +213,34 @@ public void configure(PanGestureHandler handler, ReadableMap config) {
210213
}
211214
if (config.hasKey(KEY_PAN_MIN_OFFSET_X)) {
212215
handler.setMinOffsetX(PixelUtil.toPixelFromDIP(config.getDouble(KEY_PAN_MIN_OFFSET_X)));
216+
hasCustomActivationCriteria = true;
213217
}
214218
if (config.hasKey(KEY_PAN_MIN_OFFSET_Y)) {
215219
handler.setMinOffsetY(PixelUtil.toPixelFromDIP(config.getDouble(KEY_PAN_MIN_OFFSET_Y)));
216-
}
217-
if (config.hasKey(KEY_PAN_MIN_DIST)) {
218-
handler.setMinDist(PixelUtil.toPixelFromDIP(config.getDouble(KEY_PAN_MIN_DIST)));
220+
hasCustomActivationCriteria = true;
219221
}
220222

221223
if (config.hasKey(KEY_PAN_MIN_VELOCITY)) {
222224
// This value is actually in DPs/ms, but we can use the same function as for converting
223225
// from DPs to pixels as the unit we're converting is in the numerator
224226
handler.setMinVelocity(PixelUtil.toPixelFromDIP(config.getDouble(KEY_PAN_MIN_VELOCITY)));
227+
hasCustomActivationCriteria = true;
225228
}
226229
if (config.hasKey(KEY_PAN_MIN_VELOCITY_X)) {
227230
handler.setMinVelocityX(PixelUtil.toPixelFromDIP(config.getDouble(KEY_PAN_MIN_VELOCITY_X)));
231+
hasCustomActivationCriteria = true;
228232
}
229233
if (config.hasKey(KEY_PAN_MIN_VELOCITY_Y)) {
230234
handler.setMinVelocityY(PixelUtil.toPixelFromDIP(config.getDouble(KEY_PAN_MIN_VELOCITY_Y)));
235+
hasCustomActivationCriteria = true;
236+
}
237+
238+
// PanGestureHandler sets minDist by default, if there are custom criteria specified we want
239+
// to reset that setting and use provided criteria instead.
240+
if (config.hasKey(KEY_PAN_MIN_DIST)) {
241+
handler.setMinDist(PixelUtil.toPixelFromDIP(config.getDouble(KEY_PAN_MIN_DIST)));
242+
} else if (hasCustomActivationCriteria) {
243+
handler.setMinDist(Float.MAX_VALUE);
231244
}
232245

233246
if (config.hasKey(KEY_PAN_MIN_POINTERS)) {

0 commit comments

Comments
 (0)