Skip to content
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

Fix attribution button color #252

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fun AttributionSettingsInterface.applyFromFLT(settings: FLTSettings.AttributionS
}

fun AttributionSettingsInterface.toFLT() = FLTSettings.AttributionSettings.Builder().let { settings ->
settings.setIconColor(iconColor.toLong())
settings.setIconColor(iconColor.toUInt().toLong())
settings.setPosition(position.toOrnamentPosition())
settings.setMarginLeft(marginLeft.toDouble())
settings.setMarginTop(marginTop.toDouble())
Expand All @@ -26,4 +26,4 @@ fun AttributionSettingsInterface.toFLT() = FLTSettings.AttributionSettings.Build
settings.build()
}

// End of generated file.
// End of generated file.
4 changes: 2 additions & 2 deletions example/integration_test/attribution_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ void main() {
await attribution.updateSettings(settings);
var updatedSettings = await attribution.getSettings();
expect(updatedSettings.position, OrnamentPosition.TOP_RIGHT);
expect(updatedSettings.iconColor, Colors.blue.value);
if (Platform.isIOS) {
// on iOS margins for the current position are preserved
expect(updatedSettings.marginTop, 2);
expect(updatedSettings.marginRight, 3);
} else {
// FIXME colors are decoded incorrectly for some reason
// expect(updatedSettings.iconColor, Colors.blue.value);
expect(updatedSettings.marginLeft, 1);
expect(updatedSettings.marginTop, 2);
expect(updatedSettings.marginRight, 3);
Expand Down
25 changes: 16 additions & 9 deletions ios/Classes/AttributionController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,35 @@ import UIKit
class AttributionController: NSObject, FLT_SETTINGSAttributionSettingsInterface {

func updateSettingsSettings(_ settings: FLT_SETTINGSAttributionSettings, error: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
var options = mapView.ornaments.options
switch settings.position?.value {
case .BOTTOM_LEFT:
mapView.ornaments.options.attributionButton.position = .bottomLeading
mapView.ornaments.options.attributionButton.margins = CGPoint(x: (settings.marginLeft?.CGFloat ?? 0.0)/UIScreen.main.scale, y: (settings.marginBottom?.CGFloat ?? 0.0)/UIScreen.main.scale)
options.attributionButton.position = .bottomLeading
options.attributionButton.margins = CGPoint(x: (settings.marginLeft?.CGFloat ?? 0.0)/UIScreen.main.scale, y: (settings.marginBottom?.CGFloat ?? 0.0)/UIScreen.main.scale)
case .BOTTOM_RIGHT, .none:
mapView.ornaments.options.attributionButton.position = .bottomTrailing
mapView.ornaments.options.attributionButton.margins = CGPoint(x: (settings.marginRight?.CGFloat ?? 0.0)/UIScreen.main.scale, y: (settings.marginBottom?.CGFloat ?? 0.0)/UIScreen.main.scale)
options.attributionButton.position = .bottomTrailing
options.attributionButton.margins = CGPoint(x: (settings.marginRight?.CGFloat ?? 0.0)/UIScreen.main.scale, y: (settings.marginBottom?.CGFloat ?? 0.0)/UIScreen.main.scale)
case .TOP_LEFT:
mapView.ornaments.options.attributionButton.position = .topLeading
mapView.ornaments.options.attributionButton.margins = CGPoint(x: (settings.marginLeft?.CGFloat ?? 0.0)/UIScreen.main.scale, y: (settings.marginTop?.CGFloat ?? 0.0)/UIScreen.main.scale)
options.attributionButton.position = .topLeading
options.attributionButton.margins = CGPoint(x: (settings.marginLeft?.CGFloat ?? 0.0)/UIScreen.main.scale, y: (settings.marginTop?.CGFloat ?? 0.0)/UIScreen.main.scale)
case .TOP_RIGHT:
mapView.ornaments.options.attributionButton.position = .topTrailing
mapView.ornaments.options.attributionButton.margins = CGPoint(x: (settings.marginRight?.CGFloat ?? 0.0)/UIScreen.main.scale, y: (settings.marginTop?.CGFloat ?? 0.0)/UIScreen.main.scale)
options.attributionButton.position = .topTrailing
options.attributionButton.margins = CGPoint(x: (settings.marginRight?.CGFloat ?? 0.0)/UIScreen.main.scale, y: (settings.marginTop?.CGFloat ?? 0.0)/UIScreen.main.scale)
}

mapView.ornaments.options = options
if let iconColor = settings.iconColor?.intValue {
mapView.ornaments.attributionButton.tintColor = uiColorFromHex(rgbValue: iconColor)
}
}

func getSettingsWithError(_ error: AutoreleasingUnsafeMutablePointer<FlutterError?>) -> FLT_SETTINGSAttributionSettings? {
let options = mapView.ornaments.options.attributionButton
let position = getFLT_SETTINGSOrnamentPosition(position: options.position)
let iconColor = mapView.ornaments.attributionButton.tintColor.rgb()

let settings = FLT_SETTINGSAttributionSettings.make(
withIconColor: nil,
withIconColor: NSNumber(value: iconColor),
position: .init(value: position),
marginLeft: NSNumber(value: options.margins.x * UIScreen.main.scale),
marginTop: NSNumber(value: options.margins.y * UIScreen.main.scale),
Expand Down