-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[google_maps_flutter] Convert plugin class to Swift #10545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Copyright 2013 The Flutter Authors | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import Flutter | ||
| import GoogleMaps | ||
|
|
||
| public class GoogleMapsPlugin: NSObject, FlutterPlugin { | ||
|
|
||
| public static func register(with registrar: FlutterPluginRegistrar) { | ||
| let factory = GoogleMapFactory(registrar: registrar) | ||
| registrar.register( | ||
| factory, withId: "plugins.flutter.dev/google_maps_ios", | ||
| gestureRecognizersBlockingPolicy: | ||
| FlutterPlatformViewGestureRecognizersBlockingPolicyWaitUntilTouchesEnded) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| class GoogleMapFactory: NSObject, FlutterPlatformViewFactory { | ||
| weak var registrar: FlutterPluginRegistrar? | ||
| static var sharedMapServices = GMSServices() | ||
| init(registrar: FlutterPluginRegistrar) { | ||
| self.registrar = registrar | ||
| } | ||
|
|
||
| func create(withFrame frame: CGRect, viewIdentifier viewId: Int64, arguments args: Any?) | ||
| -> any FlutterPlatformView | ||
| { | ||
| // Precache shared map services, if needed. Initializing this prepares GMSServices | ||
| // on a background thread controlled by the GoogleMaps framework. | ||
| let mapServices = GoogleMapFactory.sharedMapServices | ||
|
|
||
| return FLTGoogleMapController( | ||
| frame: frame, viewIdentifier: viewId, | ||
| creationParameters: args as! FGMPlatformMapViewCreationParams, registrar: registrar!) | ||
|
Comment on lines
30
to
36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of force casting ( Also, using // Precache shared map services, if needed. Initializing this prepares GMSServices
// on a background thread controlled by the GoogleMaps framework.
_ = GoogleMapFactory.sharedMapServices
guard let creationParams = args as? FGMPlatformMapViewCreationParams else {
// This is a programmer error on the Dart side, so crashing is reasonable.
fatalError("Invalid creation parameters for Google Map: \(String(describing: args))")
}
guard let registrar = self.registrar else {
// This should not happen in a normal lifecycle.
fatalError("Registrar is nil when creating Google Map.")
}
return FLTGoogleMapController(
frame: frame, viewIdentifier: viewId,
creationParameters: creationParams, registrar: registrar) |
||
| } | ||
|
|
||
| func createArgsCodec() -> any FlutterMessageCodec & NSObjectProtocol { | ||
| return FGMGetMessagesCodec() | ||
| } | ||
| } | ||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,9 +14,8 @@ Downloaded by pub (not CocoaPods). | |
| s.author = { 'Flutter Dev Team' => '[email protected]' } | ||
| s.source = { :http => 'https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter/ios' } | ||
| s.documentation_url = 'https://pub.dev/packages/google_maps_flutter_ios' | ||
| s.source_files = 'Classes/**/*.{h,m}' | ||
| s.source_files = 'Classes/**/*.{h,m,swift}' | ||
| s.public_header_files = 'Classes/**/*.h' | ||
| s.module_map = 'Classes/google_maps_flutter_ios.modulemap' | ||
| s.dependency 'Flutter' | ||
| # Allow any version up to the next breaking change after the latest version that | ||
| # has been confirmed to be compatible via an example in examples/. See discussion | ||
|
|
@@ -37,5 +36,6 @@ Downloaded by pub (not CocoaPods). | |
| 'LIBRARY_SEARCH_PATHS' => '$(inherited) $(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)/ $(SDKROOT)/usr/lib/swift', | ||
| 'LD_RUNPATH_SEARCH_PATHS' => '$(inherited) /usr/lib/swift', | ||
| } | ||
| s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } | ||
| s.resource_bundles = {'google_maps_flutter_ios_privacy' => ['Resources/PrivacyInfo.xcprivacy']} | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is removed because it was testing that this code and its supported declarations were all wired up correctly, and in Swift having a lazy type (class-level) variable is a built-in language feature and all of that code is just this line now, so there's nothing meaningful to test now.