يضيف التنقل إلى لوحة الأوامر أوامر تحرّك تطبيقك: افتح شاشة لا يوصل إليها أي زر بعد، بالمعاملات التي تختارها، أو ارجع، أو أعد ضبط المكدّس. ويمكنه أيضًا تسجيل كل تغيير للشاشة في وحدة التحكم.
استخدام التنقل في تطبيق سطح المكتب
الإعداد
Section titled “الإعداد”false | NavigationPluginConfig اختياري| الخيار | النوع | الافتراضي | الوصف |
|---|---|---|---|
ref مطلوب | NavigationContainerRefLike | — | مرجع الحاوية من useNavigationContainerRef()، من React Navigation أو Expo Router. استدعِ init داخل useEffect بعد الحصول عليه. |
تحتاج إضافة navigation إلى المرجع من useNavigationContainerRef()، لذا استدعِ init من داخل useEffect في المكوّن الذي يعرض حاوية التنقل، ومرّر المرجع إلى تلك الحاوية أيضًا.
import { useNavigationContainerRef } from '@react-navigation/native';import { init } from '@xerlock/client';import { useEffect } from 'react';
export const useXerlockNavigation = () => { const navigationRef = useNavigationContainerRef();
useEffect(() => { init({ navigation: { ref: navigationRef }, }); }, [navigationRef]);
return navigationRef;};يعيد الخطّاف المرجع الذي تمرّره إلى <NavigationContainer ref={…}>.
import { init } from '@xerlock/client';import { useNavigationContainerRef } from 'expo-router';import { useEffect } from 'react';
export const useXerlockNavigation = () => { const navigationRef = useNavigationContainerRef();
useEffect(() => { init({ navigation: { ref: navigationRef }, }); }, [navigationRef]);};استدعِ الخطّاف من التخطيط الجذري app/_layout.tsx. يكتشف Xerlock وجود Expo Router بنفسه، فلا حاجة
لتمرير أي شيء آخر.
تظهر الأوامر بعد تركيب حاوية التنقل.
الأشكال
Section titled “الأشكال”لا يعتمد Xerlock على React Navigation ولا على Expo Router. يكفي أن يطابق المرجع هذا الشكل:
| العضو | الوصف |
|---|---|
isReady(): boolean | Whether the navigation container has mounted and can handle actions. |
getRootState(): NavigationStateLike | undefined | Returns the navigation state of the whole tree, or undefined before it is ready. |
getCurrentRoute(): { name: string; params?: object } | undefined | Returns the focused leaf route. |
navigate(...args: never[]): void | Navigates to a screen, taking (name, params) arguments. |
dispatch(action: { type: string; payload?: object }): void | Dispatches a navigation action such as { type: 'POP', payload: { count } }. |
goBack(): void | Goes back in the focused navigator. |
canGoBack(): boolean | Whether there is a screen to go back to. |
resetRoot(state?: object): void | Replaces the whole navigation state. |
addListener(event: 'state', listener: () => void): () => void | Calls the listener after every navigation state change, and returns an unsubscribe. |
إيقافها
Section titled “إيقافها”اترك navigation، أو مرّر false. تحتاج أوامر التنقل أيضًا إلى إضافة الأوامر،
وهي مفعّلة افتراضيًا.
الحدود واستكشاف الأخطاء
Section titled “الحدود واستكشاف الأخطاء”- لا توجد أوامر تنقل: تحقّق من ضبط
navigation، ومن أن المرجع يأتي منuseNavigationContainerRef()ويُمرَّر إلى حاوية التنقل، ومن أنinitيعمل داخلuseEffect. يتجاهل Xerlock أي قيمة ليست مرجع تنقل، دون خطأ.