Skip to content

Commit

Permalink
feat: animateCameraTo - add zoom option
Browse files Browse the repository at this point in the history
  • Loading branch information
mym0404 committed Apr 14, 2024
1 parent eb94326 commit 323d6dc
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,18 @@ class RNCNaverMapViewManager : RNCNaverMapViewManagerSpec<RNCNaverMapViewWrapper
duration: Int,
easing: Int,
pivotX: Double,
pivotY: Double
pivotY: Double,
zoom: Double,
) = view.withMap {
CameraUpdate.scrollTo(LatLng(latitude, longitude))
val update = if (isValidNumber(zoom)) CameraUpdate.scrollAndZoomTo(
LatLng(
latitude,
longitude
),
zoom,
) else CameraUpdate.scrollTo(LatLng(latitude, longitude))

update
.animate(CameraAnimationUtil.numberToCameraAnimationEasing(easing), duration.toLong())
.pivot(
PointF(pivotX.toFloat(), pivotY.toFloat())
Expand Down
6 changes: 4 additions & 2 deletions android/src/oldarch/RNCNaverMapViewManagerSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ internal interface RNCNaverMapViewManagerInterface<T : ViewGroup?> {
duration: Int,
easing: Int,
pivotX: Double,
pivotY: Double
pivotY: Double,
zoom: Double,
)

fun animateCameraBy(
Expand Down Expand Up @@ -106,7 +107,8 @@ abstract class RNCNaverMapViewManagerSpec<T : ViewGroup> : ViewGroupManager<T>()
args.getInt(2),
args.getInt(3),
args.getDouble(4),
args.getDouble(5)
args.getDouble(5),
args.getDouble(6),
)

"animateCameraBy" -> animateCameraBy(
Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
# your application. You should enable this flag either if you want
# to write custom TurboModules/Fabric components OR use libraries that
# are providing them.
newArchEnabled=false
newArchEnabled=true
# Use this property to enable or disable the Hermes JS engine.
# If set to false, you will be using JSC instead.
hermesEnabled=true
16 changes: 7 additions & 9 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
NaverMapPolygonOverlay,
NaverMapCircleOverlay,
NaverMapMarkerOverlay,
type Camera,
} from '@mj-studio/react-native-naver-map';
import Slider from '@react-native-community/slider';
import { request, PERMISSIONS } from 'react-native-permissions';
Expand All @@ -22,11 +23,11 @@ const jejuRegion: Region = {
latitudeDelta: 0.38,
longitudeDelta: 0.8,
};
// const jejuCamera: Partial<Camera> = {
// latitude: jejuRegion.latitude + jejuRegion.latitudeDelta / 2,
// longitude: jejuRegion.longitude + jejuRegion.longitudeDelta / 2,
// zoom: 8.5,
// };
const jejuCamera: Camera = {
latitude: jejuRegion.latitude + jejuRegion.latitudeDelta / 2,
longitude: jejuRegion.longitude + jejuRegion.longitudeDelta / 2,
zoom: 16,
};

/**
* @private
Expand Down Expand Up @@ -220,10 +221,7 @@ export default function App() {
<Button
title={'Move to'}
onPress={() => {
ref.current?.animateCameraTo({
latitude: 33.3932536781,
longitude: 126.55746544,
});
ref.current?.animateCameraTo(jejuCamera);
}}
/>
<Button
Expand Down
6 changes: 4 additions & 2 deletions ios/RNCNaverMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,15 @@ - (void)animateCameraTo:(double)latitude
duration:(NSInteger)duration
easing:(NSInteger)easing
pivotX:(double)pivotX
pivotY:(double)pivotY {
pivotY:(double)pivotY
zoom:(double)zoom {
[_view animateCameraTo:latitude
longitude:longitude
duration:duration
easing:easing
pivotX:pivotX
pivotY:pivotY];
pivotY:pivotY
zoom:zoom];
}

- (void)animateCameraBy:(double)x
Expand Down
3 changes: 2 additions & 1 deletion ios/RNCNaverMapViewImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ using namespace facebook::react;
duration:(NSInteger)duration
easing:(NSInteger)easing
pivotX:(double)pivotX
pivotY:(double)pivotY;
pivotY:(double)pivotY
zoom:(double)zoom;
- (void)animateCameraBy:(double)x
y:(double)y
duration:(NSInteger)duration
Expand Down
8 changes: 6 additions & 2 deletions ios/RNCNaverMapViewImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,13 @@ - (void)animateCameraTo:(double)latitude
duration:(NSInteger)duration
easing:(NSInteger)easing
pivotX:(double)pivotX
pivotY:(double)pivotY {
pivotY:(double)pivotY
zoom:(double)zoom {
NMFCameraUpdate* update =
[NMFCameraUpdate cameraUpdateWithScrollTo:NMGLatLngMake(latitude, longitude)];
isValidNumber(zoom)
? [NMFCameraUpdate cameraUpdateWithScrollTo:NMGLatLngMake(latitude, longitude)
zoomTo:zoom]
: [NMFCameraUpdate cameraUpdateWithScrollTo:NMGLatLngMake(latitude, longitude)];

update.animation = getEasingAnimation(easing);
update.animationDuration = (NSTimeInterval)((double)duration) / 1000;
Expand Down
6 changes: 4 additions & 2 deletions ios/RNCNaverMapViewManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@ - (UIView*)view {
: (NSInteger)duration easing
: (NSInteger)easing pivotX
: (double)pivotX pivotY
: (double)pivotY, latitude longitude
: (double)pivotY zoom
: (double)zoom, latitude longitude
: longitude duration
: duration easing
: easing pivotX
: pivotX pivotY
: pivotY)
: pivotY zoom
: zoom)
QUICK_RCT_EXPORT_COMMAND_METHOD_PARAMS(animateCameraBy, x
: (double)x y
: (double)y duration
Expand Down
16 changes: 13 additions & 3 deletions src/component/NaverMapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,9 @@ export interface NaverMapViewRef {
/**
* 카메라를 애니메이션과 함께 이동시킵니다.
*/
animateCameraTo: (params: Coord & CameraMoveBaseParams) => void;
animateCameraTo: (
params: Coord & CameraMoveBaseParams & { zoom?: number }
) => void;
/**
* 카메라를 특정 위치만큼 델타값으로 애니메이션과 함께 이동시킵니다.
*/
Expand Down Expand Up @@ -494,7 +496,14 @@ export const NaverMapView = forwardRef(
useImperativeHandle(
ref,
() => ({
animateCameraTo: ({ duration, easing, latitude, longitude, pivot }) => {
animateCameraTo: ({
duration,
easing,
latitude,
longitude,
pivot,
zoom = Const.NULL_NUMBER,
}) => {
if (innerRef.current) {
Commands.animateCameraTo(
innerRef.current,
Expand All @@ -503,7 +512,8 @@ export const NaverMapView = forwardRef(
duration ?? Const.DEFAULT_ANIM_DURATION,
cameraEasingToNumber(easing ?? Const.DEFAULT_EASING),
pivot?.x ?? 0.5,
pivot?.y ?? 0.5
pivot?.y ?? 0.5,
zoom
);
}
},
Expand Down
3 changes: 2 additions & 1 deletion src/spec/RNCNaverMapViewNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ interface NaverMapNativeCommands {
duration?: Int32,
easing?: Int32 /*'EaseIn' | 'None' | 'Linear' | 'Fly' | 'EaseOut'*/,
pivotX?: Double,
pivotY?: Double
pivotY?: Double,
zoom?: Double
) => void;
animateCameraBy: (
ref: React.ElementRef<ComponentType>,
Expand Down

0 comments on commit 323d6dc

Please sign in to comment.