diff --git a/ios/RNMBX/RNMBXLocationModuleV11.swift b/ios/RNMBX/RNMBXLocationModuleV11.swift index 3e66a17368..55a821240e 100644 --- a/ios/RNMBX/RNMBXLocationModuleV11.swift +++ b/ios/RNMBX/RNMBXLocationModuleV11.swift @@ -11,8 +11,8 @@ class RNMBXLocation: NSObject { var timestamp: Date? = nil - func toJSON() -> [String:Any?] { - var coords: [String:Any?] = [:] + func toJSON() -> [String:Any] { + var coords: [String:Any] = [:] if let location = location { coords = coords.merging([ @@ -251,11 +251,11 @@ class RNMBXLocationModule: RCTEventEmitter { throttler.cancel() } - @objc func getLastKnownLocation() -> RNMBXLocation? { + @objc func getLastKnownLocation() -> [String: Any]? { let last = RNMBXLocation() last.heading = _locationProvider.latestHeading last.location = _locationProvider.getLastObservedLocation() - return last + return last.toJSON() } @objc diff --git a/src/utils/index.ts b/src/utils/index.ts index e5547f77f2..d057b30a53 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import React from 'react'; +import React, { ReactNode } from 'react'; import { findNodeHandle, Platform, @@ -70,14 +70,14 @@ export function runNativeMethod( } export function cloneReactChildrenWithProps( - children: Parameters[0], + children: ReactNode, propsToAdd: { [key: string]: string } = {}, ) { if (!children) { return null; } - let foundChildren = null; + let foundChildren: typeof children[] | null = null; if (!Array.isArray(children)) { foundChildren = [children]; @@ -86,9 +86,19 @@ export function cloneReactChildrenWithProps( } const filteredChildren = foundChildren.filter((child) => !!child); // filter out falsy children, since some can be null - return React.Children.map(filteredChildren, (child) => - React.cloneElement(child, propsToAdd), - ); + return React.Children.map(filteredChildren, (child) => { + if (!React.isValidElement(child)) { + return child; + } + + if (child.type === React.Fragment) { + // If the child is a Fragment, return it without adding props + return child; + } + + // Otherwise, clone and add props + return React.cloneElement(child, propsToAdd); + }); } export function resolveImagePath(imageRef: ImageSourcePropType): string {