Skip to content

Issues with Google Maps / Mapbox etc inside a stack #15

@adamiprinciples

Description

@adamiprinciples

I've got a very simple setup using parts of the example code to get me going. However I'm having issues using libraries like Google Maps or Mapbox where the code has to inject the map into the DOM. Mapbox gives me errors that the container isn't valid and Google just fails silently.

Both work when I'm not using a stack but as soon as I do things behave strangely.

I'm using code from the example folder and I've created what I think is the simplest possible approach

index.tsx

import { SplashScreen } from "@capacitor/splash-screen";
import React from "react";
import ReactDOM from "react-dom/client";

import "./app.css";
import Base from "./base";

/* Render root UI */
const root = document.getElementById("root");

if (root) {
  ReactDOM.createRoot(root).render(<Base />);
}

SplashScreen.hide({
  fadeOutDuration: 100,
});

base.tsx

import { NativeNavigationProvider } from "capacitor-native-navigation-react";
import {
  nativeNavigationNavigatorOptions,
  nativeNavigationReact,
} from "./init";

import React from "react";
import {
  NativeNavigation,
  StackSpec,
  ViewSpec,
} from "capacitor-native-navigation";
import { Routes, Route } from "react-router-dom";
import { NativeNavigationRouter } from "capacitor-native-navigation-react-router";
import Root from "./root";

export default function Base(): React.ReactElement {
  React.useEffect(() => {
    void setupStack({
      path: "/root",
      title: "Root",
      options: {
        bar: {
          background: {
            color: "#336699",
          },
          title: {
            color: "#DFEFEF",
            font: {
              name: "Solway",
              size: 26,
            },
          },
          buttons: {
            color: "#DDEEFF",
            font: {
              name: "Solway",
            },
          },
        },
      },
    });
  }, []);

  return (
    <NativeNavigationProvider value={nativeNavigationReact}>
      <div>
        <NativeNavigationRouter navigation={nativeNavigationNavigatorOptions}>
          <Routes>
            <Route path="root" element={<Root />} />
          </Routes>
        </NativeNavigationRouter>
      </div>
    </NativeNavigationProvider>
  );
}

async function setupStack(options: {
  path: string;
  title: string;
  options?: Partial<StackSpec>;
  viewOptions?: Partial<ViewSpec>;
}) {
  const stackRoot = await NativeNavigation.present({
    component: {
      alias: "rootStack",
      type: "stack",
      components: [
        {
          type: "view",
          path: options?.path,
          title: options?.title,
          ...options.viewOptions,
        },
      ],
      state: {
        fromRootStack: true,
      },
      ...options.options,
    },
    animated: true,
  });
  console.log("INIT: created", stackRoot.id);
}

root.tsx

import React from "react";
import { APIProvider, Map } from "@vis.gl/react-google-maps";

export default function Root(): React.ReactElement {
  return (
    <div>
      MAP
      <APIProvider apiKey={"REDACTED"}>
        <Map
          style={{ width: "100vw", height: "100vh" }}
          defaultCenter={{ lat: 22.54992, lng: 0 }}
          defaultZoom={3}
          gestureHandling={"greedy"}
          disableDefaultUI={true}
        />
      </APIProvider>
    </div>
  );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions