import * as React from "react" ; import { BackHandler , GestureResponderEvent , Linking , TouchableHighlight , TouchableHighlightProps } from "react-native" ; import { MemoryRouter , MemoryRouterProps , Navigate , NavigateOptions , Outlet , Route , Router , Routes , createRoutesFromChildren , generatePath , matchRoutes , matchPath , resolvePath , renderMatches , useHref , useInRouterContext , useLocation , useMatch , useNavigate , useNavigationType , useOutlet , useParams , useResolvedPath , useRoutes , useOutletContext } from "react-router" ; import type { To } from "react-router" ; import URLSearchParams from "@ungap/url-search-params" ; export { MemoryRouter , Navigate , Outlet , Route , Router , Routes , createRoutesFromChildren , generatePath , matchRoutes , matchPath , resolvePath , renderMatches , useHref , useInRouterContext , useLocation , useMatch , useNavigate , useNavigationType , useOutlet , useParams , useResolvedPath , useRoutes , useOutletContext } ; export type { IndexRouteProps , LayoutRouteProps , Location , MemoryRouterProps , NavigateFunction , NavigateOptions , NavigateProps , NavigationType , Navigator , OutletProps , Params , Path , PathMatch , PathRouteProps , RouteMatch , RouteObject , RouteProps , RouterProps , RoutesProps , To } from "react-router" ; internal export { UNSAFE_NavigationContext , UNSAFE_LocationContext , UNSAFE_RouteContext } from "react-router" ; export interface NativeRouterProps extends MemoryRouterProps { } /**
 * A <Router> that runs on React Native.
 */ export function NativeRouter ( props ) { return < MemoryRouter { ... props } / > ; } export interface LinkProps extends TouchableHighlightProps { children ? : React . ReactNode ; onPress ? : ( event : GestureResponderEvent ) => void ; replace ? : boolean ; state ? : any ; to : To ; } /**
 * A <TouchableHighlight> that navigates to a different URL when touched.
 */ export function Link ( { onPress , replace = false , state , to , ... rest } ) { let internalOnPress = useLinkPressHandler ( to , { replace , state } ) ; function handlePress ( event ) { if ( onPress ) onPress ( event ) ; if ( ! event . defaultPrevented ) { internalOnPress ( event ) ; } } return < TouchableHighlight { ... rest } onPress = { handlePress } / > ; } const HardwareBackPressEventType = "hardwareBackPress" ; const URLEventType = "url" ; /**
 * Handles the press behavior for router `<Link>` components. This is useful if
 * you need to create custom `<Link>` components with the same press behavior we
 * use in our exported `<Link>`.
 */ export function useLinkPressHandler ( to , { replace , state } = { } ) { let navigate = useNavigate ( ) ; return function handlePress ( ) { navigate ( to , { replace , state } ) ; } ; } /**
 * Enables support for the hardware back button on Android.
 */ export function useHardwareBackButton ( ) { React . useEffect ( ( ) => { function handleHardwardBackPress ( ) { return undefined ; } BackHandler . addEventListener ( HardwareBackPressEventType , handleHardwardBackPress ) ; return ( ) => { BackHandler . removeEventListener ( HardwareBackPressEventType , handleHardwardBackPress ) ; } ; } , [ ] ) ; } export { useHardwareBackButton as useAndroidBackButton } ; /**
 * Enables deep linking, both on the initial app launch and for
 * subsequent incoming links.
 */ export function useDeepLinking ( ) { let navigate = useNavigate ( ) ; React . useEffect ( ( ) => { let current = true ; Linking . getInitialURL ( ) . then ( url => { if ( current ) { if ( url ) navigate ( trimScheme ( url ) ) ; } } ) ; return ( ) => { current = false ; } ; } , [ navigate ] ) ; React . useEffect ( ( ) => { function handleURLChange ( event ) { navigate ( trimScheme ( event . url ) ) ; } Linking . addEventListener ( URLEventType , handleURLChange ) ; return ( ) => { Linking . removeEventListener ( URLEventType , handleURLChange ) ; } ; } , [ navigate ] ) ; } function trimScheme ( url ) { return url . replace ( /^.*?:\/\// , "" ) ; } /**
 * A convenient wrapper for accessing individual query parameters via the
 * URLSearchParams interface.
 */ export function useSearchParams ( defaultInit ? ) { let defaultSearchParamsRef = React . useRef ( createSearchParams ( defaultInit ) ) ; let location = useLocation ( ) ; let searchParams = React . useMemo ( ( ) => { let searchParams = createSearchParams ( location . search ) ; for ( let key of defaultSearchParamsRef . current . keys ( ) ) { if ( ! searchParams . has ( key ) ) { defaultSearchParamsRef . current . getAll ( key ) . forEach ( value => { searchParams . append ( key , value ) ; } ) ; } } return searchParams ; } , [ location . search ] ) ; let navigate = useNavigate ( ) ; let setSearchParams = React . useCallback ( ( nextInit , navigateOpts ) => { navigate ( "?" + createSearchParams ( nextInit ) , navigateOpts ) ; } , [ navigate ] ) ; return [ searchParams , setSearchParams ] ; } type SetURLSearchParams = ( nextInit ? : URLSearchParamsInit | undefined , navigateOpts ? : NavigateOptions | undefined ) => void ; export type ParamKeyValuePair = [ string , string ] ; export type URLSearchParamsInit = string | ParamKeyValuePair [ ] | Record < string , string | string [ ] > | URLSearchParams ; /**
 * Creates a URLSearchParams object using the given initializer.
 *
 * This is identical to `new URLSearchParams(init)` except it also
 * supports arrays as values in the object form of the initializer
 * instead of just strings. This is convenient when you need multiple
 * values for a given key, but don't want to use an array initializer.
 *
 * For example, instead of:
 *
 *   let searchParams = new URLSearchParams([
 *     ['sort', 'name'],
 *     ['sort', 'price']
 *   ]);
 *
 * you can do:
 *
 *   let searchParams = createSearchParams({
 *     sort: ['name', 'price']
 *   });
 */ export function createSearchParams ( init = "" ) { return new URLSearchParams ( typeof init === "string" || Array . isArray ( init ) || init instanceof URLSearchParams ? init : Object . keys ( init ) . reduce ( ( memo , key ) => { let value = init [ key ] ; return memo . concat ( Array . isArray ( value ) ? value . map ( v => [ key , v ] ) : [ [ key , value ] ] ) ; } , [ ] as ParamKeyValuePair [ ] ) ) ; }