-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat/#56] 앱 셸과의 postMessage 브리지 추가 - safe-area 색 전달 #57
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { useEffect } from "react"; | ||
|
|
||
| import type { ScreenBackground } from "@/components/ui/ScreenLayout"; | ||
| import { isInAppShell, postBridgeMessage } from "@/lib/bridge/bridge"; | ||
| import { SAFE_AREA_COLORS_MESSAGE_TYPE } from "@/lib/bridge/messages/safeAreaColors"; | ||
|
|
||
| // 화면 배경 ↔ WDS 시맨틱 토큰. index.css가 Tailwind 색으로 별칭 연결해 둔 그 변수들이다. | ||
| const BACKGROUND_CSS_VARIABLES: Record<ScreenBackground, string> = { | ||
| alternative: "--semantic-background-normal-alternative", | ||
| normal: "--semantic-background-normal-normal", | ||
| }; | ||
|
|
||
| function readCssVariable(name: string): string { | ||
| return getComputedStyle(document.documentElement) | ||
| .getPropertyValue(name) | ||
| .trim(); | ||
| } | ||
|
|
||
| // 앱은 WebView 위아래에 세이프에어리어 인셋 높이만큼 스트립을 깔고, 맞닿는 웹 화면과 같은 색으로 | ||
| // 칠해 경계선을 없앤다. 앱은 웹의 DOM을 볼 수 없으므로(별도 저장소·별도 배포, WebView 안은 | ||
| // 픽셀만 보인다) 웹이 자기 색을 알려주지 않으면 알 방법이 없다. | ||
| // | ||
| // hex를 앱에 복사해 두면 화면이 늘거나 토큰이 바뀔 때마다 두 저장소가 따로 어긋난다(#56) — | ||
| // 그래서 상수가 아니라 getComputedStyle로 지금 적용된 값을 읽어서 보낸다. 다크 테마가 붙어도 | ||
| // 같은 경로로 따라간다. | ||
| // | ||
| // 어느 색을 보낼지는 라우트 11개를 실측해서 나온 규칙 그대로다. | ||
| // top = 컬럼 배경 | ||
| // bottom = Bottom Nav가 있으면 Nav 배경(bg-background-normal), 없으면 컬럼 배경이 곧 바닥 | ||
| export function useNativeSafeAreaColors( | ||
| background: ScreenBackground, | ||
| hasBottomNav: boolean, | ||
| ) { | ||
| useEffect(() => { | ||
| if (!isInAppShell()) { | ||
| return; | ||
| } | ||
|
|
||
| const top = readCssVariable(BACKGROUND_CSS_VARIABLES[background]); | ||
| const bottom = hasBottomNav | ||
| ? readCssVariable(BACKGROUND_CSS_VARIABLES.normal) | ||
| : top; | ||
|
|
||
| // 토큰을 못 읽었으면(WDS 로드 전 등) 보내지 않는다 — 앱이 자기 기본값을 유지하는 편이 | ||
| // 빈 문자열을 받아 검정으로 칠하는 것보다 낫다. | ||
| if (!top || !bottom) { | ||
| return; | ||
| } | ||
|
|
||
| postBridgeMessage(SAFE_AREA_COLORS_MESSAGE_TYPE, { bottom, top }); | ||
| }, [background, hasBottomNav]); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /** | ||
| * 웹 → 앱 postMessage 브리지. | ||
| * | ||
| * `window.ReactNativeWebView.postMessage(JSON.stringify({ type, payload }))`로 보낸다. | ||
| * `type`은 메시지 표식, `payload`는 메시지별 본문이다. 송신하는 쪽은 봉투 형식을 모르고 | ||
| * `postBridgeMessage(type, payload)`만 부른다. | ||
| * | ||
| * 수신부: stream-client-app의 `src/features/webview/bridge/bridge.ts`. | ||
| * | ||
| * 메시지 추가 절차: | ||
| * 1. `messages/<이름>.ts`에 type 상수 · payload 인터페이스 (앱과 같은 이름·같은 필드) | ||
| * 2. 아래 `BridgePayloads`에 한 줄 등록 — `postBridgeMessage`의 타입은 여기서 파생된다 | ||
| * 3. stream-client-app에 같은 type 상수로 파서·핸들러 작성 (PR을 서로 링크) | ||
| */ | ||
|
|
||
| import { | ||
| SAFE_AREA_COLORS_MESSAGE_TYPE, | ||
| type SafeAreaColorsPayload, | ||
| } from "@/lib/bridge/messages/safeAreaColors"; | ||
|
|
||
| // stream-client-app(WebView 셸)이 주입하는 전역. 브라우저로 열면 없다. | ||
| declare global { | ||
| interface Window { | ||
| ReactNativeWebView?: { postMessage: (message: string) => void }; | ||
| } | ||
| } | ||
|
|
||
| interface BridgePayloads { | ||
| [SAFE_AREA_COLORS_MESSAGE_TYPE]: SafeAreaColorsPayload; | ||
| } | ||
|
|
||
| type BridgeMessageType = keyof BridgePayloads; | ||
|
|
||
| /** 앱 셸 안에서 열렸는지. 브라우저·개발 뷰에서는 `false`. */ | ||
| export function isInAppShell(): boolean { | ||
| return window.ReactNativeWebView !== undefined; | ||
| } | ||
|
|
||
| /** | ||
| * 앱 셸에 메시지를 보낸다. 셸 밖(브라우저)이면 아무것도 하지 않는다. | ||
| * 단방향이라 앱이 받았는지는 알 수 없다 — 앱은 모르는 메시지·형식 불일치를 조용히 버린다. | ||
| */ | ||
| export function postBridgeMessage<K extends BridgeMessageType>( | ||
| type: K, | ||
| payload: BridgePayloads[K], | ||
| ): void { | ||
| window.ReactNativeWebView?.postMessage(JSON.stringify({ payload, type })); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /** | ||
| * 세이프에어리어 스트립 색 메시지. | ||
| * | ||
| * 앱은 WebView 위아래에 세이프에어리어 인셋 높이만큼 스트립을 깔고, 맞닿는 웹 화면과 같은 색으로 | ||
| * 칠해 경계선을 없앤다. 그 색은 화면마다 다르고 웹만 알기 때문에 웹이 보낸다. | ||
| * | ||
| * 수신부: stream-client-app의 `src/features/webview/bridge/messages/safeAreaColors.ts`. | ||
| * 표식 문자열과 payload 필드 이름은 양쪽이 맞춰야 한다. | ||
| */ | ||
|
|
||
| export const SAFE_AREA_COLORS_MESSAGE_TYPE = "safeAreaColors"; | ||
|
|
||
| export interface SafeAreaColorsPayload { | ||
| bottom: string; | ||
| top: string; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Coordinate the receiver rollout before relying on this envelope.
If an app build uses the current
stream-client-appmain-branch parser, it readstopandbottomfrom the outer message. This line puts both fields inpayload, so that parser rejects every safe-area update and keeps its default strip colors. The proposed app bridge acceptspayload, but it is a separate, open change. Confirm that the updated app receiver ships before this message format is expected to resolve the visible boundary; otherwise, provide a compatible receiver during the transition. (raw.githubusercontent.com)🤖 Prompt for AI Agents