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

feat: 서랍장 서비스 등록 페이지 네이티브 웹뷰 연결 #216

Merged
merged 8 commits into from
Jul 7, 2024

Conversation

2wndrhs
Copy link
Member

@2wndrhs 2wndrhs commented Jun 18, 2024

1️⃣ 어떤 작업을 했나요? (Summary)

기존 코드에 영향을 미치지 않는 변경사항

  • drawer/pages/Register.tsx
    • Android, ios 웹뷰로 서랍장 서비스 등록 페이지에 접속하면 네이티브에서 유저의 accessToken을 받아오는 기능을 구현하였습니다.

2️⃣ 알아두시면 좋아요!

  • Android 웹뷰에서 서랍장 서비스 등록 페이지에 접속

    1. Andorid 네이티브에 정의된 함수인 `Android.getAccessToken() 호출
    2. Andoird 네이티브에서는 유저의 accessToken을 가져와 웹뷰에 정의된 자바스크립트 함수인 window.setAccessToken()을 호출
    3. setAccessToken 함수는 네이티브로부터 accessToken을 받아 api 싱글톤 객체에 등록 -> 추후 API 요청에 이용
  • ios 웹뷰에서 서랍장 서비스 등록 페이지에 접속

    1. iOS 네이티브에 정의된 컨트롤러에 유저의 accessToken을 요청(window.webkit.messageHandlers.ios.postMessage("getAccessToken"))
    2. ios 네이티브에서 유저의 accessToken을 가져와 웹뷰에 정의된 자바스크립트 함수인 window.setAccessToken()을 호출
    3. setAccessToken 함수는 네이티브로부터 accessToken을 받아 api 싱글톤 객체에 등록 -> 추후 API 요청에 이용

3️⃣ 추후 작업

  • 웹뷰에서 정상적으로 서랍장 서비스 등록이 이루어지는지 확인하기

4️⃣ 체크리스트 (Checklist)

  • main 브랜치의 최신 코드를 pull 받았나요?

@@ -40,6 +57,22 @@ export const Register = () => {
}
};

useEffect(() => {
const getAccessTokenFromNative = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

앞으로 해당 객체들을 사용할 때 마다 if문으로 undefined 체크를 해야 할 것 같습니다.
initialize 할 수 있는 기능을 추가해야 할 것 같은데 아래처럼 클래스 두고 인스턴스 생성해서 쓰는건 별로일까요?

class NativeAPI {
  constructor(iosHandler, androidHandler, api) {
    this.initialize(iosHandler, androidHandler);
  }

  initialize(iosHandler, androidHandler) {
    if (!iosHandler || !androidHandler) {
      throw new Error("No valid handler found for Native API.");
    }
    this.handler = iosHandler;
    this.handler = androidHandler;
  }
  // awesome logics..
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

어썸 로직이네요................................

Copy link
Member Author

Choose a reason for hiding this comment

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

고민을 해봤는데 해당 코드는 웹뷰로 접속하는 페이지가 많을 때 유용할 것 같은데 숨쉴때는 서랍장 서비스 등록 페이지만 웹뷰로 접속하는 상황이라 현재 상황에서는 지금 코드를 유지해도 될 것 같아요

웹뷰로 접속하는 페이지가 많아지고 반복되는 로직을 제거해야할 필요성을 느낄 때 제안해주신 코드를 도입하면 좋지 않을까 싶네요..!

어썸 코드 감사합니다

Copy link
Member

@seocylucky seocylucky left a comment

Choose a reason for hiding this comment

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

일단 어푸룹해두겠습니다!!
혹시 관련 코드 작성하실 때 참고하신 문서같은게 있으신가요?! 웹뷰 연결 처음 봐서.. 궁금해서 여쭤봅니당

window.Android랑 window.webkit 접근하실 때 엠제이 말처럼 실제로 존재하는지 여부를 확인하는 코드가 있으면 좋을 것 같아용

수고하셨습니다👍🏻👍🏻👍🏻

Copy link
Collaborator

@nijuy nijuy left a comment

Choose a reason for hiding this comment

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

쭌 혹시 여기서 mutate 끝나고 페이지 이동하는 코드 추가해줄 수 있나요 ㅠㅠ!?!
등록 성공해도 등록 페이지에 머물러 있어서 안된 것처럼 보여가지고용
웹뷰 연결이랑은 무관한데 등록이랑 관련 있는 내용이라 혹시 모바일 팀에서 이걸로 문의 들어올까봐 남깁니더~~...

(이 브랜치에 해놔야 모바일팀에 전달한 링크 (184번 브랜치 배포한) 에 바로 반영 될 거 같아서요!)

};

window.setAccessToken = (accessToken: string) => {
api.setAccessToken(accessToken, Date.now() + 5 * 60 * 1000);
Copy link
Collaborator

Choose a reason for hiding this comment

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

모바일 토큰의 브라우저 상 유효시간을 받아온 시각 + 5분으로 설정한 거는 쭌이 임의로 정한건가요? 혹시 타자가 느려서 웹뷰 접속 후 5분 지나면........ 어쩌지 하는 걱정이 있어가지고

유효 시간은 넉넉하게 해두고 프로덕트 등록 mutate 완료 후에 토큰 삭제하는 건 별로일까요?!?

Copy link
Member

Choose a reason for hiding this comment

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

넉넉히 10분..?

Copy link
Member Author

@2wndrhs 2wndrhs Jun 21, 2024

Choose a reason for hiding this comment

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

네이티브 쪽에서 accessToken만 받아오는거라 제가 임의로 5분으로 설정했는데 생각해보니 조금 짧은 감이 있네요..
1시간으로 넉넉히 잡아놓겠습니다 -> 96c3bde

유저가 서비스 등록 후에 바로 다른 서비스를 등록할 수 있으니 토큰은 살려두는게 나을 것 같아요..!

Copy link
Collaborator

Choose a reason for hiding this comment

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

천잰가

@2wndrhs
Copy link
Member Author

2wndrhs commented Jun 21, 2024

쭌 혹시 여기서 mutate 끝나고 페이지 이동하는 코드 추가해줄 수 있나요 ㅠㅠ!?! 등록 성공해도 등록 페이지에 머물러 있어서 안된 것처럼 보여가지고용 웹뷰 연결이랑은 무관한데 등록이랑 관련 있는 내용이라 혹시 모바일 팀에서 이걸로 문의 들어올까봐 남깁니더~~...

맞네요 서비스 등록 성공하면 페이지 이동시키는 코드 추가해놓겠습니다..! -> b5379a5

웹뷰에서는 서비스 등록 성공시 웹뷰 안에서 페이지 이동을 시키는게 어색할 것 같아서 다시 네이티브 쪽으로 성공 여부를 알려줘서 네이티브 쪽에서 처리하는게 자연스러울 것 같네요 -> 이 부분은 안드, ios 팀이랑 얘기해보겠습니다

@2wndrhs
Copy link
Member Author

2wndrhs commented Jun 21, 2024

일단 어푸룹해두겠습니다!! 혹시 관련 코드 작성하실 때 참고하신 문서같은게 있으신가요?! 웹뷰 연결 처음 봐서.. 궁금해서 여쭤봅니당

저도 웹뷰 연결이 처음이라 지피티씨 도움 받아서 구현했습니다🤗
찾아본 자료 중에서는 아래 유튜브 영상이 가장 좋았습니다!
모두의 웹뷰 - 우아콘2023

@2wndrhs 2wndrhs force-pushed the feat/#184-service-register-webview branch from 7a174ae to 8e5e87a Compare July 7, 2024 13:43
@2wndrhs 2wndrhs merged commit 0ffb2c4 into develop Jul 7, 2024
@2wndrhs 2wndrhs deleted the feat/#184-service-register-webview branch July 7, 2024 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
drawer feat New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT] 서랍장 서비스 등록 페이지 웹뷰 연결
5 participants