Skip to content

Commit 86281dd

Browse files
committed
- add iOS implementation (draft)
1 parent adf9be3 commit 86281dd

File tree

4 files changed

+157
-10
lines changed

4 files changed

+157
-10
lines changed

src/libs/Mapbox.Maui/Mapbox.Maui.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
<PackageReference Include="Xamarin.AndroidX.Annotation" Version="1.8.0.1" />
101101
</ItemGroup>
102102
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">
103-
<PackageReference Include="MapboxMapsObjC.iOS" Version="11.5.2.3" />
103+
<PackageReference Include="MapboxMapsObjC.iOS" Version="11.5.2.5" />
104104
<PackageReference Include="MapboxMaps.iOS" Version="11.5.2" />
105105
</ItemGroup>
106106
<ItemGroup>

src/libs/Mapbox.Maui/Platforms/iOS/MapboxViewHandler.Location.cs

+153-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using MapboxMapsObjC;
22
using MapboxMaui.Locations;
3+
using ObjCRuntime;
34

45
namespace MapboxMaui;
56
using PlatformView = MapViewContainer;
@@ -19,23 +20,167 @@ private TMBLocationManager Plugin
1920

2021
public bool Enabled
2122
{
22-
get => throw new NotImplementedException();
23-
set => throw new NotImplementedException();
23+
get => Plugin.Options.PuckType is not null;
24+
set
25+
{
26+
if (!value)
27+
{
28+
Plugin.Options.PuckType = null;
29+
return;
30+
}
31+
32+
var options = Plugin.Options;
33+
options.PuckType = TMBPuck2DConfiguration.MakeDefaultWithShowBearing(false);
34+
35+
Plugin.Options = options;
36+
}
2437
}
2538

2639
public bool PulsingEnabled
2740
{
28-
get => throw new NotImplementedException();
29-
set => throw new NotImplementedException();
41+
get
42+
{
43+
if (Plugin.Options.PuckType is null) return false;
44+
45+
try
46+
{
47+
var puck2D = Runtime.GetNSObject<TMBPuck2DConfiguration>(
48+
Plugin.Options.PuckType.Handle
49+
);
50+
51+
52+
return puck2D.Pulsing != null;
53+
}
54+
catch
55+
{
56+
// When the native value isn't a valid TMBPuck2DConfiguration,
57+
// Runtime.GetNSObject will throw an error
58+
return false;
59+
}
60+
}
61+
set
62+
{
63+
if (Plugin.Options.PuckType is null) return;
64+
65+
try
66+
{
67+
var options = Plugin.Options;
68+
var puck2D = Runtime.GetNSObject<TMBPuck2DConfiguration>(
69+
options.PuckType.Handle
70+
);
71+
72+
if (value is false)
73+
{
74+
// TODO Set this property to NULL
75+
// or just set the inner property, IsEnabled, to false?
76+
puck2D.Pulsing = null;
77+
}
78+
else
79+
{
80+
puck2D.Pulsing = puck2D.Pulsing ?? TMBPuck2DConfigurationPulsing.Default();
81+
}
82+
options.PuckType = puck2D;
83+
Plugin.Options = options;
84+
}
85+
catch
86+
{
87+
// When the native value isn't a valid TMBPuck2DConfiguration,
88+
// Runtime.GetNSObject will throw an error
89+
return;
90+
}
91+
}
3092
}
3193
public bool ShowAccuracyRing
3294
{
33-
get => throw new NotImplementedException();
34-
set => throw new NotImplementedException();
95+
get
96+
{
97+
if (Plugin.Options.PuckType is null) return false;
98+
99+
try
100+
{
101+
var puck2D = Runtime.GetNSObject<TMBPuck2DConfiguration>(
102+
Plugin.Options.PuckType.Handle
103+
);
104+
105+
return puck2D.ShowsAccuracyRing == true;
106+
}
107+
catch
108+
{
109+
// When the native value isn't a valid TMBPuck2DConfiguration,
110+
// Runtime.GetNSObject will throw an error
111+
return false;
112+
}
113+
}
114+
set
115+
{
116+
if (Plugin.Options.PuckType is null) return;
117+
118+
try
119+
{
120+
var puck2D = Runtime.GetNSObject<TMBPuck2DConfiguration>(
121+
Plugin.Options.PuckType.Handle
122+
);
123+
124+
if (puck2D.Pulsing is null)
125+
{
126+
return;
127+
}
128+
129+
puck2D.ShowsAccuracyRing = value;
130+
}
131+
catch
132+
{
133+
// When the native value isn't a valid TMBPuck2DConfiguration,
134+
// Runtime.GetNSObject will throw an error
135+
return;
136+
}
137+
}
35138
}
36139
public float PulsingMaxRadius
37140
{
38-
get => throw new NotImplementedException();
39-
set => throw new NotImplementedException();
141+
get
142+
{
143+
if (Plugin.Options.PuckType is null) return float.NegativeInfinity;
144+
145+
try
146+
{
147+
var puck2D = Runtime.GetNSObject<TMBPuck2DConfiguration>(
148+
Plugin.Options.PuckType.Handle
149+
);
150+
151+
return puck2D.Pulsing?.Radius.Constant?.FloatValue
152+
?? float.NegativeInfinity;
153+
}
154+
catch
155+
{
156+
// When the native value isn't a valid TMBPuck2DConfiguration,
157+
// Runtime.GetNSObject will throw an error
158+
return float.NegativeInfinity;
159+
}
160+
}
161+
set
162+
{
163+
if (Plugin.Options.PuckType is null) return;
164+
165+
try
166+
{
167+
var puck2D = Runtime.GetNSObject<TMBPuck2DConfiguration>(
168+
Plugin.Options.PuckType.Handle
169+
);
170+
171+
if (puck2D.Pulsing is null)
172+
{
173+
return;
174+
}
175+
176+
puck2D.Pulsing.Radius = TMBPuck2DConfigurationPulsingRadius.FromConstant(value);
177+
}
178+
catch
179+
{
180+
// When the native value isn't a valid TMBPuck2DConfiguration,
181+
// Runtime.GetNSObject will throw an error
182+
return;
183+
}
184+
}
40185
}
41186
}

src/qs/MapboxMauiQs/MapboxMauiQs.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
</Compile>
107107
</ItemGroup>
108108
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">
109-
<PackageReference Include="MapboxMapsObjC.iOS" Version="11.5.2.3" />
109+
<PackageReference Include="MapboxMapsObjC.iOS" Version="11.5.2.5" />
110110
<PackageReference Include="MapboxMaps.iOS" Version="11.5.2" />
111111

112112
<Compile Include="..\..\libs\Mapbox.Maui\Platforms\iOS\**\**\*.cs">

src/qs/MapboxMauiQs/Platforms/iOS/Info.plist

+2
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@
3030
<string>Assets.xcassets/appicon.appiconset</string>
3131
<key>MBXAccessToken.x</key>
3232
<string>YOUR_MAPBOX_ACCESS_TOKEN</string>
33+
<key>NSLocationWhenInUseUsageDescription</key>
34+
<string>The app needs location to demo features like pulsing.</string>
3335
</dict>
3436
</plist>

0 commit comments

Comments
 (0)