Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

카카오톡 친구 추가 공유 기능 #319

Merged
merged 16 commits into from
Aug 17, 2024
Merged

카카오톡 친구 추가 공유 기능 #319

merged 16 commits into from
Aug 17, 2024

Conversation

JuTaK97
Copy link
Collaborator

@JuTaK97 JuTaK97 commented Jul 14, 2024

스펙 문서 : https://www.notion.so/wafflestudio/97cc32635c314af5883f299f21b0a1bb?pvs=4#4414c4b92fda420696a3cd792cee9211

변경사항

크게 RN 구현과 카카오 SDK 사용으로 나눠진다. 커밋 단위로 보면 편함~

카카오 SDK 사용

카카오톡 메시지에 보여지는 모습을 구성하는 FeedTemplate 이라는 것을 조립한 뒤, 카카오 SDK가 만들어주는 intent 를 실행한다.
우선 내가 대충 만든 템플릿으로 되어 있다.

FeedTemplate을 만들 때 Content에 androidExecutionParams, iosExecutionParams 라는 것을 map 타입으로 받는다. 이곳에 넣은 key-value들은 쿼리 파라미터의 형태로 딥링크에 들어가게 된다. 유저가 카카오톡 메시지의 버튼을 누르면, kakao${app-key}://kakaolink?key1=value1&key2=value2 이렇게 된 딥링크가 실행된다.

RN 구현

1단계: 친구탭에서 카카오톡 공유 버튼을 눌렀을 때

image

RN 화면의 카카오톡 공유 버튼을 누르면 add-friend-kakao 이벤트가 네이티브에게 전달되고, 파라미터에는 RN이 서버에게 받아 온 requestToken이 들어 있다. 네이티브는 이 requestToken을 담아 카카오톡 메시지를 발송한다.

2단계: 카카오톡 공유 딥링크를 눌렀을 때

RootActivity에서는 딥링크를 파싱해서 최초 랜딩 탭을 설정해 준다. 또한 SNUTTReactRootView 에서는 딥링크를 파싱해서 requestToken을 얻은 뒤, EmitterModule 로 RN에게 이벤트를 전송한다.
이때 안전하게 ReactContext를 얻을 필요가 있어서 reactInstanceManager.addReactInstanceEventListener 를 이용해 reactContext의 생성을 subscribe하도록 구현했다.
EmitterModule가 requestToken을 RN에게 전송할 때는 약간의 추가 구현이 있다.
RN은 최초에 register 라는 이벤트를 네이티브에게 쏴 주는데, 파라미터에는 EVENT_TYPE이 들어가 있고 이는 RN 이 해당 EVENT_TYPE 에 대한 리스너의 설정을 완료했다는 뜻이다.
이때 add-friend-kakao 이벤트 리스너가 등록됐는지 (=register 로 전달됐었는지) 를 체크하는데, 만약 아직 등록되지 않았으면 tasks 에 저장해 놨다가 나중에 해당 eventType의 register가 왔을 때 한번에 flush하도록 구현되어 있다.

딥링크를 파싱하는 부분이 RootActivity와 SNUTTReactRootView로 쪼개졌다는 것이 약간의 고민 사항

@JuTaK97 JuTaK97 requested a review from a team as a code owner July 14, 2024 04:25
Comment on lines +48 to +55
REGISTER -> {
val eventType = parameters?.getString(EVENT_TYPE) ?: return

// RN 에서 리스너를 등록했다고 알려 온 eventType 에 대해, 쌓여 있던 task 를 수행한다.
registeredListeners.add(eventType)
tasks[eventType]?.forEach { it.invoke() }
tasks[eventType]?.clear()
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분은, RN에서 이벤트 받는 부분이 아니라 RN에게 이벤트 보낼 때 사용
다다음 커밋과 함께 보길..

@plgafhd
Copy link
Collaborator

plgafhd commented Jul 25, 2024

하 어렵네... ㅋㅋㅋㅋ

@JuTaK97 JuTaK97 merged commit fbedf80 into develop Aug 17, 2024
3 checks passed
@JuTaK97 JuTaK97 deleted the feat/kakao-link branch August 17, 2024 15:48
@JuTaK97 JuTaK97 mentioned this pull request Aug 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants