From a9cfdd979e0554393e15307a373a980913ca3c78 Mon Sep 17 00:00:00 2001 From: Ravindra Gupta <ravindra.gupta@capgemini.com> Date: Thu, 27 Jul 2023 18:44:28 +0530 Subject: [PATCH] Updated iOS Project --- ReproducerApp/App.tsx | 40 ++++++++++++------ ReproducerApp/ios/Podfile | 41 +++++++++++++++---- .../ReproducerApp.xcodeproj/project.pbxproj | 36 +++++++++++++++- .../ios/ReproducerApp/AppDelegate.mm | 7 ++++ 4 files changed, 101 insertions(+), 23 deletions(-) diff --git a/ReproducerApp/App.tsx b/ReproducerApp/App.tsx index 05254ac..a305338 100644 --- a/ReproducerApp/App.tsx +++ b/ReproducerApp/App.tsx @@ -5,36 +5,34 @@ * @format */ -import React, { useRef } from 'react'; -import type { PropsWithChildren } from 'react'; +import React, { useReducer } from 'react'; import { - SafeAreaView, - ScrollView, - StatusBar, + Button, StyleSheet, - Text, useColorScheme, View, } from 'react-native'; -import { - Colors, -} from 'react-native/Libraries/NewAppScreen'; +import { Colors } from 'react-native/Libraries/NewAppScreen'; -import MapView, { Marker, enableLatestRenderer, PROVIDER_GOOGLE } from 'react-native-maps'; +import MapView, { + Marker, + enableLatestRenderer, + PROVIDER_GOOGLE, +} from 'react-native-maps'; enableLatestRenderer(); function App(): JSX.Element { const isDarkMode = useColorScheme() === 'dark'; + const forceUpdate = useReducer(x => x + 1, 0)[1]; const backgroundStyle = { backgroundColor: isDarkMode ? Colors.darker : Colors.lighter, }; - return ( - // <SafeAreaView style={backgroundStyle}> - <View style={styles.container}> + const renderMap = () => { + return ( <MapView style={styles.map} provider={PROVIDER_GOOGLE} @@ -72,6 +70,22 @@ function App(): JSX.Element { description={'description'} /> </MapView> + ); + }; + + let map = renderMap(); + + return ( + // <SafeAreaView style={backgroundStyle}> + <View style={styles.container}> + {map} + <Button + color={'red'} + title={'Re-render Map'} + onPress={() => { + forceUpdate(); + }} + /> </View> // </SafeAreaView> ); diff --git a/ReproducerApp/ios/Podfile b/ReproducerApp/ios/Podfile index 403498b..fd43ec8 100644 --- a/ReproducerApp/ios/Podfile +++ b/ReproducerApp/ios/Podfile @@ -5,7 +5,7 @@ require Pod::Executable.execute_command('node', ['-p', {paths: [process.argv[1]]}, )', __dir__]).strip -platform :ios, min_ios_version_supported +platform :ios, 13 prepare_react_native_project! # If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set. @@ -17,13 +17,13 @@ prepare_react_native_project! # dependencies: { # ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}), # ``` -flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled +# flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled -linkage = ENV['USE_FRAMEWORKS'] -if linkage != nil - Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green - use_frameworks! :linkage => linkage.to_sym -end +# linkage = ENV['USE_FRAMEWORKS'] +# if linkage != nil +# Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green +# use_frameworks! :linkage => linkage.to_sym +# end target 'ReproducerApp' do config = use_native_modules! @@ -31,6 +31,18 @@ target 'ReproducerApp' do # Flags change depending on the env values. flags = get_default_flags() + $static_framework = [ + 'react-native-maps', + 'react-native-google-maps', + 'Google-Maps-iOS-Utils', + 'GoogleMaps' + ] + + pod 'react-native-google-maps', :path => '../node_modules/react-native-maps' + pod 'GoogleMaps' + pod 'Google-Maps-iOS-Utils' + pod 'GoogleUtilities', :modular_headers => true + use_react_native!( :path => config[:reactNativePath], # Hermes is now enabled by default. Disable by setting this flag to false. @@ -40,7 +52,7 @@ target 'ReproducerApp' do # # Note that if you have use_frameworks! enabled, Flipper will not work and # you should disable the next line. - :flipper_configuration => flipper_config, + :flipper_configuration => FlipperConfiguration.disabled, # An absolute path to your application root. :app_path => "#{Pod::Config.instance.installation_root}/.." ) @@ -50,6 +62,19 @@ target 'ReproducerApp' do # Pods for testing end + pre_install do |installer| + Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {} + installer.pod_targets.each do |pod| + if $static_framework.include?(pod.name) + def pod.build_type; + # Uncomment one line depending on your CocoaPods version + Pod::BuildType.static_library # >= 1.9 + # Pod::Target::BuildType.static_library # < 1.9 + end + end + end + end + post_install do |installer| # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202 react_native_post_install( diff --git a/ReproducerApp/ios/ReproducerApp.xcodeproj/project.pbxproj b/ReproducerApp/ios/ReproducerApp.xcodeproj/project.pbxproj index c01a9b9..70b6cda 100644 --- a/ReproducerApp/ios/ReproducerApp.xcodeproj/project.pbxproj +++ b/ReproducerApp/ios/ReproducerApp.xcodeproj/project.pbxproj @@ -487,11 +487,19 @@ CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = 1; ENABLE_BITCODE = NO; + "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64; INFOPLIST_FILE = ReproducerApp/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); + LIBRARY_SEARCH_PATHS = ( + "$(SDKROOT)/usr/lib/swift", + "$(inherited)", + "\"${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}\"", + /usr/lib/swift, + "$(PODS_ROOT)/../../node_modules/react-native-maps/lib/ios/AirMaps", + ); MARKETING_VERSION = 1.0; OTHER_LDFLAGS = ( "$(inherited)", @@ -513,11 +521,19 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = 1; + "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64; INFOPLIST_FILE = ReproducerApp/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); + LIBRARY_SEARCH_PATHS = ( + "$(SDKROOT)/usr/lib/swift", + "$(inherited)", + "\"${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}\"", + /usr/lib/swift, + "$(PODS_ROOT)/../../node_modules/react-native-maps/lib/ios/AirMaps", + ); MARKETING_VERSION = 1.0; OTHER_LDFLAGS = ( "$(inherited)", @@ -564,7 +580,7 @@ COPY_PHASE_STRIP = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; - "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = ""; + "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = i386; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; @@ -580,6 +596,14 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "${PODS_CONFIGURATION_BUILD_DIR}/ReactCommon-Samples/ReactCommon_Samples.framework/Headers", + "${PODS_CONFIGURATION_BUILD_DIR}/ReactCommon/ReactCommon.framework/Headers/react/nativemodule/core", + "${PODS_CONFIGURATION_BUILD_DIR}/ReactCommon-Samples/ReactCommon_Samples.framework/Headers/platform/ios", + "${PODS_CONFIGURATION_BUILD_DIR}/React-NativeModulesApple/React_NativeModulesApple.framework/Headers", + "${PODS_CONFIGURATION_BUILD_DIR}/React-graphics/React_graphics.framework/Headers/react/renderer/graphics/platform/ios", + ); IPHONEOS_DEPLOYMENT_TARGET = 12.4; LD_RUNPATH_SEARCH_PATHS = ( /usr/lib/swift, @@ -635,7 +659,7 @@ COPY_PHASE_STRIP = YES; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; - "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = ""; + "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = i386; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; @@ -644,6 +668,14 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "${PODS_CONFIGURATION_BUILD_DIR}/ReactCommon-Samples/ReactCommon_Samples.framework/Headers", + "${PODS_CONFIGURATION_BUILD_DIR}/ReactCommon/ReactCommon.framework/Headers/react/nativemodule/core", + "${PODS_CONFIGURATION_BUILD_DIR}/ReactCommon-Samples/ReactCommon_Samples.framework/Headers/platform/ios", + "${PODS_CONFIGURATION_BUILD_DIR}/React-NativeModulesApple/React_NativeModulesApple.framework/Headers", + "${PODS_CONFIGURATION_BUILD_DIR}/React-graphics/React_graphics.framework/Headers/react/renderer/graphics/platform/ios", + ); IPHONEOS_DEPLOYMENT_TARGET = 12.4; LD_RUNPATH_SEARCH_PATHS = ( /usr/lib/swift, diff --git a/ReproducerApp/ios/ReproducerApp/AppDelegate.mm b/ReproducerApp/ios/ReproducerApp/AppDelegate.mm index 7eaac38..9d78831 100644 --- a/ReproducerApp/ios/ReproducerApp/AppDelegate.mm +++ b/ReproducerApp/ios/ReproducerApp/AppDelegate.mm @@ -1,6 +1,7 @@ #import "AppDelegate.h" #import <React/RCTBundleURLProvider.h> +#import <GoogleMaps/GoogleMaps.h> @implementation AppDelegate @@ -11,6 +12,12 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( // They will be passed down to the ViewController used by React Native. self.initialProps = @{}; + NSString *mapsKey = @"QUl6YVN5Q1k0OVJpQmVZX2ZxRTh1b0c2WmF1VG9RU0VpNzZLNnB3"; + NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:mapsKey options:0]; + NSString *decodedKey = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding]; + + [GMSServices provideAPIKey:decodedKey]; + return [super application:application didFinishLaunchingWithOptions:launchOptions]; }