Skip to content

Commit

Permalink
feat: add get padding
Browse files Browse the repository at this point in the history
  • Loading branch information
illuminati1911 committed Dec 16, 2024
1 parent c071e99 commit 359d160
Show file tree
Hide file tree
Showing 17 changed files with 251 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,8 @@ class GoogleMapsAutoViewMessageHandler(private val viewRegistry: GoogleMapsViewR
override fun setPadding(padding: MapPaddingDto) {
getView().setPadding(padding)
}

override fun getPadding(): MapPaddingDto {
return getView().getPadding()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ abstract class GoogleMapsBaseMapView(
private var _minZoomLevelPreference: Float? = null
private var _maxZoomLevelPreference: Float? = null

private var _mapOptions: MapOptions? = null

// Nullable variable to hold the callback function
private var _mapReadyCallback: ((Result<Unit>) -> Unit)? = null
private var _loadedCallbackPending = false
Expand Down Expand Up @@ -101,6 +103,7 @@ abstract class GoogleMapsBaseMapView(
init {
_minZoomLevelPreference = mapOptions.googleMapOptions.minZoomPreference
_maxZoomLevelPreference = mapOptions.googleMapOptions.maxZoomPreference
_mapOptions = mapOptions
}

protected fun mapReady() {
Expand Down Expand Up @@ -943,6 +946,7 @@ abstract class GoogleMapsBaseMapView(
}

fun setPadding(padding: MapPaddingDto) {
_mapOptions?.padding = padding
getMap()
.setPadding(
padding.left.toInt(),
Expand All @@ -951,4 +955,8 @@ abstract class GoogleMapsBaseMapView(
padding.bottom.toInt(),
)
}

fun getPadding(): MapPaddingDto {
return _mapOptions?.padding ?: MapPaddingDto(0, 0, 0, 0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -479,4 +479,8 @@ class GoogleMapsViewMessageHandler(private val viewRegistry: GoogleMapsViewRegis
override fun setPadding(viewId: Long, padding: MapPaddingDto) {
getView(viewId.toInt()).setPadding(padding)
}

override fun getPadding(viewId: Long): MapPaddingDto {
return getView(viewId.toInt()).getPadding()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ package com.google.maps.flutter.navigation

import com.google.android.gms.maps.GoogleMapOptions

class MapOptions(val googleMapOptions: GoogleMapOptions, val padding: MapPaddingDto?) {}
class MapOptions(val googleMapOptions: GoogleMapOptions, var padding: MapPaddingDto?) {}
Original file line number Diff line number Diff line change
Expand Up @@ -2206,6 +2206,8 @@ interface MapViewApi {

fun setPadding(viewId: Long, padding: MapPaddingDto)

fun getPadding(viewId: Long): MapPaddingDto

companion object {
/** The codec used by MapViewApi. */
val codec: MessageCodec<Any?> by lazy { MapViewApiCodec }
Expand Down Expand Up @@ -4441,6 +4443,29 @@ interface MapViewApi {
channel.setMessageHandler(null)
}
}
run {
val channel =
BasicMessageChannel<Any?>(
binaryMessenger,
"dev.flutter.pigeon.google_navigation_flutter.MapViewApi.getPadding",
codec,
)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val viewIdArg = args[0].let { if (it is Int) it.toLong() else it as Long }
var wrapped: List<Any?>
try {
wrapped = listOf<Any?>(api.getPadding(viewIdArg))
} catch (exception: Throwable) {
wrapped = wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
}
}
}
Expand Down Expand Up @@ -6485,6 +6510,8 @@ interface AutoMapViewApi {

fun setPadding(padding: MapPaddingDto)

fun getPadding(): MapPaddingDto

companion object {
/** The codec used by AutoMapViewApi. */
val codec: MessageCodec<Any?> by lazy { AutoMapViewApiCodec }
Expand Down Expand Up @@ -8207,6 +8234,27 @@ interface AutoMapViewApi {
channel.setMessageHandler(null)
}
}
run {
val channel =
BasicMessageChannel<Any?>(
binaryMessenger,
"dev.flutter.pigeon.google_navigation_flutter.AutoMapViewApi.getPadding",
codec,
)
if (api != null) {
channel.setMessageHandler { _, reply ->
var wrapped: List<Any?>
try {
wrapped = listOf<Any?>(api.getPadding())
} catch (exception: Throwable) {
wrapped = wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,8 @@ class GoogleMapsAutoViewMessageHandler: AutoMapViewApi {
func setPadding(padding: MapPaddingDto) throws {
try getView().setPadding(padding: padding)
}

func getPadding() throws -> MapPaddingDto {
try getView().getPadding()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,15 @@ public class GoogleMapsNavigationView: NSObject, FlutterPlatformView, ViewSettle
right: CGFloat(padding.right)
)
}

func getPadding() throws -> MapPaddingDto {
MapPaddingDto(
top: Int64(_mapView.padding.top),
left: Int64(_mapView.padding.left),
bottom: Int64(_mapView.padding.bottom),
right: Int64(_mapView.padding.right)
)
}
}

extension GoogleMapsNavigationView: GMSMapViewNavigationUIDelegate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,4 +509,8 @@ class GoogleMapsNavigationViewMessageHandler: MapViewApi {
func setPadding(viewId: Int64, padding: MapPaddingDto) throws {
try getView(viewId).setPadding(padding: padding)
}

func getPadding(viewId: Int64) throws -> MapPaddingDto {
try getView(viewId).getPadding()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,7 @@ protocol MapViewApi {
func clearCircles(viewId: Int64) throws
func registerOnCameraChangedListener(viewId: Int64) throws
func setPadding(viewId: Int64, padding: MapPaddingDto) throws
func getPadding(viewId: Int64) throws -> MapPaddingDto
}

/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
Expand Down Expand Up @@ -3952,6 +3953,25 @@ enum MapViewApiSetup {
} else {
setPaddingChannel.setMessageHandler(nil)
}
let getPaddingChannel = FlutterBasicMessageChannel(
name: "dev.flutter.pigeon.google_navigation_flutter.MapViewApi.getPadding",
binaryMessenger: binaryMessenger,
codec: codec
)
if let api {
getPaddingChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let viewIdArg = args[0] is Int64 ? args[0] as! Int64 : Int64(args[0] as! Int32)
do {
let result = try api.getPadding(viewId: viewIdArg)
reply(wrapResult(result))
} catch {
reply(wrapError(error))
}
}
} else {
getPaddingChannel.setMessageHandler(nil)
}
}
}

Expand Down Expand Up @@ -5893,6 +5913,7 @@ protocol AutoMapViewApi {
func registerOnCameraChangedListener() throws
func isAutoScreenAvailable() throws -> Bool
func setPadding(padding: MapPaddingDto) throws
func getPadding() throws -> MapPaddingDto
}

/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
Expand Down Expand Up @@ -7303,6 +7324,23 @@ enum AutoMapViewApiSetup {
} else {
setPaddingChannel.setMessageHandler(nil)
}
let getPaddingChannel = FlutterBasicMessageChannel(
name: "dev.flutter.pigeon.google_navigation_flutter.AutoMapViewApi.getPadding",
binaryMessenger: binaryMessenger,
codec: codec
)
if let api {
getPaddingChannel.setMessageHandler { _, reply in
do {
let result = try api.getPadding()
reply(wrapResult(result))
} catch {
reply(wrapError(error))
}
}
} else {
getPaddingChannel.setMessageHandler(nil)
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions lib/src/google_maps_auto_view_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,11 @@ class GoogleMapsAutoViewController {
.setPaddingForAuto(padding: padding);
}

// Gets the map padding from the map view.
Future<EdgeInsets> getPadding({required int viewId}) async {
return GoogleMapsNavigationPlatform.instance.getPaddingForAuto();
}

Future<bool> isAutoScreenAvailable() {
return GoogleMapsNavigationPlatform.instance.isAutoScreenAvailable();
}
Expand Down
5 changes: 5 additions & 0 deletions lib/src/google_maps_map_view_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -371,4 +371,9 @@ class GoogleMapViewController {
return GoogleMapsNavigationPlatform.instance
.setPadding(viewId: _viewId, padding: padding);
}

// Gets the map padding from the map view.
Future<EdgeInsets> getPadding({required int viewId}) async {
return GoogleMapsNavigationPlatform.instance.getPadding(viewId: _viewId);
}
}
6 changes: 6 additions & 0 deletions lib/src/google_navigation_flutter_platform_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,9 @@ abstract mixin class MapViewAPIInterface {
// Sets the map padding for the map view.
Future<void> setPadding({required int viewId, required EdgeInsets padding});

// Gets the map padding from the map view.
Future<EdgeInsets> getPadding({required int viewId});

/// Get navigation view marker event stream from the navigation view.
Stream<MarkerEvent> getMarkerEventStream({required int viewId});

Expand Down Expand Up @@ -775,6 +778,9 @@ abstract mixin class AutoMapViewAPIInterface {
// Sets the map padding for the auto map view.
Future<void> setPaddingForAuto({required EdgeInsets padding});

// Gets the map padding from the auto map view.
Future<EdgeInsets> getPaddingForAuto();

/// Get custom navigation auto event stream from the auto view.
Stream<CustomNavigationAutoEvent> getCustomNavigationAutoEventStream();

Expand Down
11 changes: 11 additions & 0 deletions lib/src/method_channel/common_auto_view_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,17 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface {
right: padding.right.toInt()));
}

// Gets the map padding from the map view.
@override
Future<EdgeInsets> getPaddingForAuto() async {
final MapPaddingDto padding = await _viewApi.getPadding();
return EdgeInsets.only(
top: padding.top.toDouble(),
left: padding.left.toDouble(),
bottom: padding.bottom.toDouble(),
right: padding.right.toDouble());
}

@override
Future<bool> isAutoScreenAvailable() {
return _viewApi.isAutoScreenAvailable();
Expand Down
11 changes: 11 additions & 0 deletions lib/src/method_channel/common_view_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,17 @@ mixin CommonMapViewAPI on MapViewAPIInterface {
right: padding.right.toInt()));
}

// Gets the map padding from the map view.
@override
Future<EdgeInsets> getPadding({required int viewId}) async {
final MapPaddingDto padding = await _viewApi.getPadding(viewId);
return EdgeInsets.only(
top: padding.top.toDouble(),
left: padding.left.toDouble(),
bottom: padding.bottom.toDouble(),
right: padding.right.toDouble());
}

@override
Stream<MapClickEvent> getMapClickEventStream({required int viewId}) {
return _unwrapEventStream<MapClickEvent>(viewId: viewId);
Expand Down
58 changes: 58 additions & 0 deletions lib/src/method_channel/messages.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4606,6 +4606,35 @@ class MapViewApi {
return;
}
}

Future<MapPaddingDto> getPadding(int viewId) async {
const String __pigeon_channelName =
'dev.flutter.pigeon.google_navigation_flutter.MapViewApi.getPadding';
final BasicMessageChannel<Object?> __pigeon_channel =
BasicMessageChannel<Object?>(
__pigeon_channelName,
pigeonChannelCodec,
binaryMessenger: __pigeon_binaryMessenger,
);
final List<Object?>? __pigeon_replyList =
await __pigeon_channel.send(<Object?>[viewId]) as List<Object?>?;
if (__pigeon_replyList == null) {
throw _createConnectionError(__pigeon_channelName);
} else if (__pigeon_replyList.length > 1) {
throw PlatformException(
code: __pigeon_replyList[0]! as String,
message: __pigeon_replyList[1] as String?,
details: __pigeon_replyList[2],
);
} else if (__pigeon_replyList[0] == null) {
throw PlatformException(
code: 'null-error',
message: 'Host platform returned null value for non-null return value.',
);
} else {
return (__pigeon_replyList[0] as MapPaddingDto?)!;
}
}
}

class _ImageRegistryApiCodec extends StandardMessageCodec {
Expand Down Expand Up @@ -8682,6 +8711,35 @@ class AutoMapViewApi {
return;
}
}

Future<MapPaddingDto> getPadding() async {
const String __pigeon_channelName =
'dev.flutter.pigeon.google_navigation_flutter.AutoMapViewApi.getPadding';
final BasicMessageChannel<Object?> __pigeon_channel =
BasicMessageChannel<Object?>(
__pigeon_channelName,
pigeonChannelCodec,
binaryMessenger: __pigeon_binaryMessenger,
);
final List<Object?>? __pigeon_replyList =
await __pigeon_channel.send(null) as List<Object?>?;
if (__pigeon_replyList == null) {
throw _createConnectionError(__pigeon_channelName);
} else if (__pigeon_replyList.length > 1) {
throw PlatformException(
code: __pigeon_replyList[0]! as String,
message: __pigeon_replyList[1] as String?,
details: __pigeon_replyList[2],
);
} else if (__pigeon_replyList[0] == null) {
throw PlatformException(
code: 'null-error',
message: 'Host platform returned null value for non-null return value.',
);
} else {
return (__pigeon_replyList[0] as MapPaddingDto?)!;
}
}
}

class _AutoViewEventApiCodec extends StandardMessageCodec {
Expand Down
2 changes: 2 additions & 0 deletions pigeons/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ abstract class MapViewApi {

void registerOnCameraChangedListener(int viewId);
void setPadding(int viewId, MapPaddingDto padding);
MapPaddingDto getPadding(int viewId);
}

@HostApi(dartHostTestHandler: 'TestImageRegistryApi')
Expand Down Expand Up @@ -1371,6 +1372,7 @@ abstract class AutoMapViewApi {
void registerOnCameraChangedListener();
bool isAutoScreenAvailable();
void setPadding(MapPaddingDto padding);
MapPaddingDto getPadding();
}

@FlutterApi()
Expand Down
Loading

0 comments on commit 359d160

Please sign in to comment.