volga-volga / react-native-yamap

React Native Yandex Maps | Яндекс Карты | Yandex.MapKit implementation for react native | YandexMaps
144 stars 80 forks source link

Не работает с expo-cli #261

Open KerAm-js opened 8 months ago

KerAm-js commented 8 months ago

Добрый день! Пытался использовать библиотеку в проекте на expo-cli. Приложение падает с ошибкой "cannot read property 'init' of null". Ошибка указывает на файл Yamap.js (строка 62) из пакетных файлов библиотеки.

Как я понял, проблема начинается с файла app.config.ts

Вот мой код

import { type ExpoConfig } from "@expo/config-types";
import { withAppDelegate, type ConfigPlugin } from "expo/config-plugins";

const config: ExpoConfig = {
  name: "my-app",
  slug: "my-app",
  version: "1.0.0",
  orientation: "portrait",
  icon: "./assets/icon.png",
  userInterfaceStyle: "light",
  splash: {
    image: "./assets/splash.png",
    resizeMode: "cover",
    backgroundColor: "#ffffff",
  },
  assetBundlePatterns: ["**/*"],
  ios: {
    supportsTablet: false,
    bundleIdentifier: $MY_IDENTIFIER_HERE$
  },
  android: {
    adaptiveIcon: {
      foregroundImage: "./assets/adaptive-icon.png",
      backgroundColor: "#ffffff",
    },
  },
  web: {
    favicon: "./assets/favicon.png",
  },
  extra: {
    mapKitApiKey: $MY_API_KEY_HERE$,
  },
};

const withYandexMaps: ConfigPlugin = (config) => {
  return withAppDelegate(config, async (config) => {
    const appDelegate = config.modResults;

    // Add import
    if (
      !appDelegate.contents.includes(
        "#import <YandexMapsMobile/YMKMapKitFactory.h>"
      )
    ) {
      // Replace the first line with the intercom import
      appDelegate.contents = appDelegate.contents.replace(
        /#import "AppDelegate.h"/g,
        `#import "AppDelegate.h"\n#import <YandexMapsMobile/YMKMapKitFactory.h>`
      );
    }

    const mapKitMethodInvocations = [
      `[YMKMapKit setApiKey:@"${config.extra?.mapKitApiKey}"];`,
      `[YMKMapKit setLocale:@"ru_RU"];`,
      `[YMKMapKit mapKit];`,
    ]
      .map((line) => `\t${line}`)
      .join("\n");

    // Add invocation
    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
    if (!appDelegate.contents.includes(mapKitMethodInvocations)) {
      appDelegate.contents = appDelegate.contents.replace(
        /\s+return YES;/g,
        `\n\n${mapKitMethodInvocations}\n\n\treturn YES;`
      );
    }

    return config;
  });
};

export default withYandexMaps(config);

Я пытался запустить приложение с использованием expo prebuild, команда сгенерировала папку ios и я запустил приложение через XCode. В итоге получил следующие ошибки:

  1. module map file '/Users/amir/Library/Developer/Xcode/DerivedData/myapp-droppxvmzpgrwicwsrldmghuhhch/Build/Products/Debug-iphonesimulator/EXConstants/EXConstants.modulemap' not found
  2. No such module 'ExpoModulesCore' /Users/amir/Desktop/Duna/ios/Pods/Target Support Files/Pods-myapp/ExpoModulesProvider.swift:8:8
stasovlas commented 3 months ago

@KerAm-js Удалось победить?