تخطَّ إلى المحتوى
العربية

التنقل

يضيف التنقل إلى لوحة الأوامر أوامر تحرّك تطبيقك: افتح شاشة لا يوصل إليها أي زر بعد، بالمعاملات التي تختارها، أو ارجع، أو أعد ضبط المكدّس. ويمكنه أيضًا تسجيل كل تغيير للشاشة في وحدة التحكم.

استخدام التنقل في تطبيق سطح المكتب

يقبل false | NavigationPluginConfig اختياري
NavigationPluginConfig
الخيارالنوعالافتراضيالوصف
ref مطلوبNavigationContainerRefLike—مرجع الحاوية من useNavigationContainerRef()، من React Navigation أو Expo Router. استدعِ init داخل useEffect بعد الحصول عليه.
use-xerlock-navigation.ts
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={…}>.

تظهر الأوامر بعد تركيب حاوية التنقل.

لا يعتمد Xerlock على React Navigation ولا على Expo Router. يكفي أن يطابق المرجع هذا الشكل:

NavigationContainerRefLike
العضوالوصف
isReady(): booleanWhether the navigation container has mounted and can handle actions.
getRootState(): NavigationStateLike | undefinedReturns the navigation state of the whole tree, or undefined before it is ready.
getCurrentRoute(): { name: string; params?: object } | undefinedReturns the focused leaf route.
navigate(...args: never[]): voidNavigates to a screen, taking (name, params) arguments.
dispatch(action: { type: string; payload?: object }): voidDispatches a navigation action such as { type: 'POP', payload: { count } }.
goBack(): voidGoes back in the focused navigator.
canGoBack(): booleanWhether there is a screen to go back to.
resetRoot(state?: object): voidReplaces the whole navigation state.
addListener(event: 'state', listener: () => void): () => voidCalls the listener after every navigation state change, and returns an unsubscribe.

اترك navigation، أو مرّر false. تحتاج أوامر التنقل أيضًا إلى إضافة الأوامر، وهي مفعّلة افتراضيًا.

الحدود واستكشاف الأخطاء

Section titled “الحدود واستكشاف الأخطاء”
  • لا توجد أوامر تنقل: تحقّق من ضبط navigation، ومن أن المرجع يأتي من useNavigationContainerRef() ويُمرَّر إلى حاوية التنقل، ومن أن init يعمل داخل useEffect. يتجاهل Xerlock أي قيمة ليست مرجع تنقل، دون خطأ.