mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-30 05:15:25 +08:00
refactor: change format to formatter for documentTitle option
This commit is contained in:
@@ -278,7 +278,7 @@ export default function App() {
|
|||||||
}}
|
}}
|
||||||
fallback={<Text>Loading…</Text>}
|
fallback={<Text>Loading…</Text>}
|
||||||
documentTitle={{
|
documentTitle={{
|
||||||
format: (options, route) =>
|
formatter: (options, route) =>
|
||||||
`${options?.title ?? route?.name} - React Navigation Example`,
|
`${options?.title ?? route?.name} - React Navigation Example`,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ export type LinkingOptions = {
|
|||||||
|
|
||||||
export type DocumentTitleOptions = {
|
export type DocumentTitleOptions = {
|
||||||
enabled?: boolean;
|
enabled?: boolean;
|
||||||
format?: (
|
formatter?: (
|
||||||
options: Record<string, any> | undefined,
|
options: Record<string, any> | undefined,
|
||||||
route: Route<string> | undefined
|
route: Route<string> | undefined
|
||||||
) => string;
|
) => string;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export default function useDocumentTitle(
|
|||||||
ref: React.RefObject<NavigationContainerRef>,
|
ref: React.RefObject<NavigationContainerRef>,
|
||||||
{
|
{
|
||||||
enabled = true,
|
enabled = true,
|
||||||
format = (options, route) => options?.title ?? route?.name,
|
formatter = (options, route) => options?.title ?? route?.name,
|
||||||
}: DocumentTitleOptions = {}
|
}: DocumentTitleOptions = {}
|
||||||
) {
|
) {
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
@@ -20,7 +20,7 @@ export default function useDocumentTitle(
|
|||||||
const navigation = ref.current;
|
const navigation = ref.current;
|
||||||
|
|
||||||
if (navigation) {
|
if (navigation) {
|
||||||
const title = format(
|
const title = formatter(
|
||||||
navigation.getCurrentOptions(),
|
navigation.getCurrentOptions(),
|
||||||
navigation.getCurrentRoute()
|
navigation.getCurrentRoute()
|
||||||
);
|
);
|
||||||
@@ -29,7 +29,7 @@ export default function useDocumentTitle(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return navigation?.addListener('options', (e) => {
|
return navigation?.addListener('options', (e) => {
|
||||||
const title = format(e.data.options, navigation?.getCurrentRoute());
|
const title = formatter(e.data.options, navigation?.getCurrentRoute());
|
||||||
|
|
||||||
document.title = title;
|
document.title = title;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user