我遇到react-native-gesture-handler
的问题。每当我将react-native-gesture-handler
链接到我的项目时,它就会停止工作并显示此错误。但是从我的项目取消链接react-native-gesture-handler
后,应用程序可以正常工作。但是,由于需要从多个屏幕导航,因此需要手势处理程序。
首先,我认为这是react-native
版本的问题,因为我使用的是react-native
版本0.57.0,但是它在0.58.0和0.55.4上也不起作用。
package com.swmansion.gesturehandler.react;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import com.facebook.react.uimanager.PointerEvents;
import com.facebook.react.uimanager.ReactPointerEventsView;
import com.facebook.react.views.view.ReactViewGroup;
import com.swmansion.gesturehandler.PointerEventsConfig;
import com.swmansion.gesturehandler.ViewConfigurationHelper;
public class RNViewConfigurationHelper implements ViewConfigurationHelper {
@Override
public PointerEventsConfig getPointerEventsConfigForView(View view) {
PointerEvents pointerEvents;
pointerEvents = view instanceof ReactPointerEventsView ?
((ReactPointerEventsView) view).getPointerEvents() :
PointerEvents.AUTO;
// Views that are disabled should never be the target of pointer events. However, their children
// can be because some views (SwipeRefreshLayout) use enabled but still have children that can
// be valid targets.
if (!view.isEnabled()) {
if (pointerEvents == PointerEvents.AUTO) {
return PointerEventsConfig.BOX_NONE;
} else if (pointerEvents == PointerEvents.BOX_ONLY) {
return PointerEventsConfig.NONE;
}
}
switch (pointerEvents) {
case BOX_ONLY: return PointerEventsConfig.BOX_ONLY;
case BOX_NONE: return PointerEventsConfig.BOX_NONE;
case NONE: return PointerEventsConfig.NONE;
}
return PointerEventsConfig.AUTO;
}
@Override
public View getChildInDrawingOrderAtIndex(ViewGroup parent, int index) {
if (parent instanceof ReactViewGroup) {
return parent.getChildAt(((ReactViewGroup) parent).getZIndexMappedChildIndex(index));
}
return parent.getChildAt(index);
}
@Override
public boolean isViewClippingChildren(ViewGroup view) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && !view.getClipChildren()) {
if (view instanceof ReactViewGroup) {
String overflow = ((ReactViewGroup) view).getOverflow();
return "hidden".equals(overflow);
}
return false;
}
return true;
}
}
答案 0 :(得分:0)
您可以尝试手动链接。
也请检查此问题: https://github.com/kmagiera/react-native-gesture-handler/issues/205
答案 1 :(得分:0)
如果在Android而不是iOS上遇到问题,则可能是您需要为符号添加polyfill。我不记得在哪里找到了它,但是我已经在自己的项目中使用了它,并且可以正常工作。只需将其粘贴在index.js中即可:
if (Platform.OS === 'android') {
if (typeof Symbol === 'undefined') {
if (Array.prototype['@@iterator'] === undefined) {
Array.prototype['@@iterator'] = function() {
let i = 0;
return {
next: () => ({
done: i >= this.length,
value: this[i++]
})
};
};
}
}
}