You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{useFocusEffect,useNavigation}from'@react-navigation/native';importtype{MapState}from'@rnmapbox/maps';importMapbox,{MarkerView,setAccessToken}from'@rnmapbox/maps';import{forwardRef,memo,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from'react';import{View}from'react-native';import{withOnyx}from'react-native-onyx';importIconfrom'@components/Icon';import*asExpensiconsfrom'@components/Icon/Expensicons';import{PressableWithoutFeedback}from'@components/Pressable';importuseThemefrom'@hooks/useTheme';importuseThemeStylesfrom'@hooks/useThemeStyles';import*asUserLocationfrom'@libs/actions/UserLocation';importcomposefrom'@libs/compose';importgetCurrentPositionfrom'@libs/getCurrentPosition';importtype{GeolocationErrorCallback}from'@libs/getCurrentPosition/getCurrentPosition.types';import{GeolocationErrorCode}from'@libs/getCurrentPosition/getCurrentPosition.types';importcolorsfrom'@styles/theme/colors';importvariablesfrom'@styles/variables';importCONSTfrom'@src/CONST';importuseLocalizefrom'@src/hooks/useLocalize';importuseNetworkfrom'@src/hooks/useNetwork';importONYXKEYSfrom'@src/ONYXKEYS';importDirectionfrom'./Direction';importtype{MapViewHandle}from'./MapViewTypes';importPendingMapViewfrom'./PendingMapView';importresponderfrom'./responder';importtype{ComponentProps,MapViewOnyxProps}from'./types';importutilsfrom'./utils';constMapView=forwardRef<MapViewHandle,ComponentProps>(({accessToken, style, mapPadding,userLocation: cachedUserLocation, styleURL, pitchEnabled, initialState, waypoints, directionCoordinates, onMapReady, interactive =true},ref)=>{const navigation =useNavigation();const{isOffline}=useNetwork();const{translate}=useLocalize();conststyles=useThemeStyles();consttheme=useTheme();constcameraRef=useRef<Mapbox.Camera>(null);const[isIdle,setIsIdle]=useState(false);constinitialLocation=useMemo(()=>initialState&&{longitude: initialState.location[0],latitude: initialState.location[1]},[initialState]);const[currentPosition,setCurrentPosition]=useState(cachedUserLocation??initialLocation);const[userInteractedWithMap,setUserInteractedWithMap]=useState(false);constshouldInitializeCurrentPosition=useRef(true);// Determines if map can be panned to user's detected// location without bothering the user. It will return// false if user has already started dragging the map or// if there are one or more waypoints present.constshouldPanMapToCurrentPosition=useCallback(()=>!userInteractedWithMap&&(!waypoints||waypoints.length===0),[userInteractedWithMap,waypoints]);constsetCurrentPositionToInitialState: GeolocationErrorCallback=useCallback((error)=>{if(error?.code!==GeolocationErrorCode.PERMISSION_DENIED||!initialLocation){return;}UserLocation.clearUserLocation();setCurrentPosition(initialLocation);},[initialLocation],);useFocusEffect(useCallback(()=>{if(isOffline){return;}if(!shouldInitializeCurrentPosition.current){return;}shouldInitializeCurrentPosition.current=false;if(!shouldPanMapToCurrentPosition()){setCurrentPositionToInitialState();return;}getCurrentPosition((params)=>{constcurrentCoords={longitude: params.coords.longitude,latitude: params.coords.latitude};setCurrentPosition(currentCoords);UserLocation.setUserLocation(currentCoords);},setCurrentPositionToInitialState);},[isOffline,shouldPanMapToCurrentPosition,setCurrentPositionToInitialState]),);useEffect(()=>{if(!currentPosition||!cameraRef.current){return;}if(!shouldPanMapToCurrentPosition()){return;}cameraRef.current.setCamera({zoomLevel: CONST.MAPBOX.DEFAULT_ZOOM,animationDuration: 1500,centerCoordinate: [currentPosition.longitude,currentPosition.latitude],});},[currentPosition,shouldPanMapToCurrentPosition]);useImperativeHandle(ref,()=>({flyTo: (location: [number,number],zoomLevel: number=CONST.MAPBOX.DEFAULT_ZOOM,animationDuration?: number)=>cameraRef.current?.setCamera({zoomLevel,centerCoordinate: location, animationDuration}),fitBounds: (northEast: [number,number],southWest: [number,number],paddingConfig?: number|number[]|undefined,animationDuration?: number|undefined)=>cameraRef.current?.fitBounds(northEast,southWest,paddingConfig,animationDuration),}),[],);// When the page loses focus, we temporarily set the "idled" state to false.// When the page regains focus, the onIdled method of the map will set the actual "idled" state,// which in turn triggers the callback.useFocusEffect(useCallback(()=>{if(!waypoints||waypoints.length===0||!isIdle){return;}if(waypoints.length===1){cameraRef.current?.setCamera({zoomLevel: CONST.MAPBOX.SINGLE_MARKER_ZOOM,animationDuration: 1500,centerCoordinate: waypoints[0].coordinate,});}else{const{southWest, northEast}=utils.getBounds(waypoints.map((waypoint)=>waypoint.coordinate),directionCoordinates,);cameraRef.current?.fitBounds(northEast,southWest,mapPadding,1000);}},[mapPadding,waypoints,isIdle,directionCoordinates]),);useEffect(()=>{constunsubscribe=navigation.addListener('blur',()=>{setIsIdle(false);});returnunsubscribe;},[navigation]);useEffect(()=>{setAccessToken(accessToken);},[accessToken]);constsetMapIdle=(e: MapState)=>{if(e.gestures.isGestureActive){return;}setIsIdle(true);if(onMapReady){onMapReady();}};constcenterMap=useCallback(()=>{if(directionCoordinates&&directionCoordinates.length>1){const{southWest, northEast}=utils.getBounds(waypoints?.map((waypoint)=>waypoint.coordinate)??[],directionCoordinates);cameraRef.current?.fitBounds(southWest,northEast,mapPadding,CONST.MAPBOX.ANIMATION_DURATION_ON_CENTER_ME);return;}cameraRef?.current?.setCamera({heading: 0,centerCoordinate: [currentPosition?.longitude??0,currentPosition?.latitude??0],animationDuration: CONST.MAPBOX.ANIMATION_DURATION_ON_CENTER_ME,zoomLevel: CONST.MAPBOX.SINGLE_MARKER_ZOOM,});},[directionCoordinates,currentPosition,mapPadding,waypoints]);constcenterCoordinate=currentPosition ? [currentPosition.longitude,currentPosition.latitude] : initialState?.location;return!isOffline&&!!accessToken&&!!currentPosition ? (<Viewstyle={[style,!interactive ? styles.pointerEventsNone : {}]}><Mapbox.MapViewstyle={{flex: 1}}styleURL={styleURL}onMapIdle={setMapIdle}onTouchStart={()=>setUserInteractedWithMap(true)}pitchEnabled={pitchEnabled}attributionPosition={{...styles.r2, ...styles.b2}}scaleBarEnabled={false}logoPosition={{...styles.l2, ...styles.b2}}// eslint-disable-next-line react/jsx-props-no-spreading{...responder.panHandlers}><Mapbox.Cameraref={cameraRef}defaultSettings={{
centerCoordinate,zoomLevel: initialState?.zoom,}}// Include centerCoordinate here as well to address the issue of incorrect coordinates// displayed after the first render when the app's storage is cleared.centerCoordinate={centerCoordinate}/><Mapbox.ShapeSourceid="user-location"shape={{type: 'FeatureCollection',features: [{type: 'Feature',geometry: {type: 'Point',coordinates: [currentPosition?.longitude??0,currentPosition?.latitude??0],},properties: {},},],}}><Mapbox.CircleLayerid="user-location-layer"sourceID="user-location"style={{circleColor: colors.blue400,circleRadius: 8,}}/></Mapbox.ShapeSource>{waypoints?.map(({coordinate, markerComponent, id})=>{constMarkerComponent=markerComponent;if(utils.areSameCoordinate([coordinate[0],coordinate[1]],[currentPosition?.longitude??0,currentPosition?.latitude??0])){returnnull;}return(<MarkerViewid={id}key={id}coordinate={coordinate}><MarkerComponent/></MarkerView>);})}{directionCoordinates&&<Directioncoordinates={directionCoordinates}/>}</Mapbox.MapView><Viewstyle={[styles.pAbsolute,styles.p5,styles.t0,styles.r0,{zIndex: 1}]}><PressableWithoutFeedbackaccessibilityRole={CONST.ROLE.BUTTON}onPress={centerMap}accessibilityLabel={translate('common.center')}><Viewstyle={styles.primaryMediumIcon}><Iconwidth={variables.iconSizeNormal}height={variables.iconSizeNormal}src={Expensicons.Crosshair}fill={theme.icon}/></View></PressableWithoutFeedback></View></View>) : (<PendingMapViewtitle={translate('distance.mapPending.title')}subtitle={isOffline ? translate('distance.mapPending.subtitle') : translate('distance.mapPending.onlineSubtitle')}style={styles.mapEditView}/>);},);exportdefaultcompose(withOnyx<ComponentProps,MapViewOnyxProps>({userLocation: {key: ONYXKEYS.USER_LOCATION,},}),memo,)(MapView);
Observed behavior and steps to reproduce
During migrating Expensify to RN 0.74+ we noticed crash of the app caused by rn mapbox
the error which we are getting is Error: Exception in HostFunction: no non-static method "Lcom/rnmapbox/rnmbx/components/mapview/NativeMapViewModule;.setHandledMapChangedEvents(Ljava/lang/Double;Lcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/Promise;)V"
Mapbox Implementation
Mapbox
Mapbox Version
default
React Native Version
0.74.2
Platform
Android
@rnmapbox/maps
version10.1.23
Standalone component to reproduce
Observed behavior and steps to reproduce
During migrating Expensify to RN 0.74+ we noticed crash of the app caused by rn mapbox
the error which we are getting is
Error: Exception in HostFunction: no non-static method "Lcom/rnmapbox/rnmbx/components/mapview/NativeMapViewModule;.setHandledMapChangedEvents(Ljava/lang/Double;Lcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/Promise;)V"
Here is a PR with migration https://github.com/Expensify/App/pull/40548/files
I also checked on newest version of rn-mapbox but its happening the same.
More logs:
React Native 0.74 upgrade logs.txt
Expected behavior
No response
Notes / preliminary analysis
No response
Additional links and references
No response
The text was updated successfully, but these errors were encountered: