가이드
네이티브 네비게이션 튜토리얼
Using @capgo/native-navigation
@capgo/native-navigation Capacitor WebView 위에 단일 풀 스크린 네이티브 탑 네비게이션, 하단 탭 크롬, 및 루트 전환 셸을 렌더링합니다. 웹 프레임워크는 여전히 경로와 콘텐츠를 소유하고 있으면서 네이티브는 앱 프레임을 소유합니다.
설치 및 동기화
bun add @capgo/native-navigation
bunx cap sync
네이티브 프레임을 구성하십시오
import { NativeNavigation } from '@capgo/native-navigation';
await NativeNavigation.configure({
contentInsetMode: 'css',
animationDuration: 360,
colors: {
tint: '#0f172a',
inactiveTint: '#64748b',
},
});
네이티브 네비게이션 바를 렌더링하십시오
await NativeNavigation.setNavbar({
title: 'Inbox',
subtitle: 'Native chrome',
transparent: true,
backButton: { visible: false },
rightItems: [
{
id: 'compose',
title: 'Compose',
icon: {
svg: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"/></svg>',
},
},
],
});
네이티브 탭 바를 렌더링하십시오
await NativeNavigation.setTabbar({
selectedId: 'inbox',
labels: true,
icons: true,
tabs: [
{
id: 'inbox',
title: 'Inbox',
icon: {
svg: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M4 4h16v16H4z"/><path d="m4 13 4 4h8l4-4"/></svg>',
},
},
{
id: 'search',
title: 'Search',
icon: {
svg: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="7"/><path d="m20 20-3-3"/></svg>',
},
},
],
});
네이티브 이벤트를 라우터에 연결하십시오
네이티브 바는 의도(intent)를 내뿜지만, 라우터는 여전히 경로 변경을 수행합니다.
await NativeNavigation.addListener('navbarBack', () => {
router.back();
});
await NativeNavigation.addListener('navbarItemTap', ({ id }) => {
if (id === 'compose') router.push('/compose');
});
await NativeNavigation.addListener('tabSelect', ({ id }) => {
router.push(`/${id}`);
});
경로 변경 애니메이션
일반 웹 경로 업데이트 주변에 전환 거래를 사용하세요:
const transition = await NativeNavigation.beginTransition({
direction: 'forward',
});
router.push('/message/42');
await router.ready?.();
await NativeNavigation.setNavbar({
title: 'Message',
backButton: { visible: true, title: 'Inbox' },
});
await NativeNavigation.finishTransition({
id: transition.id,
direction: 'forward',
});
네이티브 인셋으로 콘텐츠를 패딩하세요
언제 contentInsetMode is css, 플러그인은 네이티브 바에 대한 CSS 변수를 작성합니다.
.page {
padding-top: var(--cap-native-navigation-top);
padding-bottom: var(--cap-native-navigation-bottom);
}
아이콘 선택
아이콘은 React 또는 Vue 노드가 아닌 네이티브 디스크립터입니다. 네이티브 애셋을 번들링하지 않으려면 SVG를 사용하세요:
const icon = {
svg: '<svg viewBox="0 0 24 24"><path d="M3 10.5 12 3l9 7.5"/></svg>',
template: true,
ios: { sfSymbol: 'house.fill' },
android: { resource: 'ic_menu_view' },
};
인라인 SVG는 path, line, polyline, polygon, circle, 및 rect,을 지원합니다. 이는 Lucide 및 Feather와 같은 일반적인 아이콘 세트를 커버합니다.
전체 참조
- GitHub: https://github.com/Cap-go/capacitor-native-navigation/
- 문서: /docs/plugins/native-navigation/