Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ios/RNMBX/RNMBXLocationModuleV11.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -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
Expand Down
22 changes: 16 additions & 6 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import React from 'react';
import React, { ReactNode } from 'react';
import {
findNodeHandle,
Platform,
Expand Down Expand Up @@ -70,14 +70,14 @@ export function runNativeMethod<ReturnType = NativeArg>(
}

export function cloneReactChildrenWithProps(
children: Parameters<typeof React.Children.map>[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];
Expand All @@ -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 {
Expand Down
Loading