dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.24k stars 1.76k forks source link

Refactor Essentials statics into interfaces/singletons #4497

Closed Redth closed 2 years ago

Redth commented 2 years ago

Historically Xamarin.Essentials API's were all static classes with static methods in them. This made mocking out their behaviour for testing much more difficult, and many ended up creating yet another abstraction on top of these API's.

We need to refactor these into interfaces and create implementations which can be set as the singleton at runtime. We can map the existing static methods to the singleton to preserve backwards source code compatibility.

See these examples: https://github.com/dotnet/maui/pull/4464 https://github.com/dotnet/maui/pull/4465 and https://github.com/dotnet/maui/pull/4466

API's to complete:

mattleibow commented 2 years ago

So looking at the various implementations so far, I think we actually need to do more than just what we have. If I was to register a service and not use the statics, I would lose a fair bit of functionality.

For example, if there is any validation or permissions checks. Right now that just lives in the static class. This should all move to the instance. But to be clean and consistent now, we can continue the way we are. In another, smaller pass we can move the logic into the instances.

antonfirsov commented 2 years ago

@sps014 giving a heads up if you plan to go on working on this, so we avoid duplicate work :) I plan to go top-down in alphabetic order, started with Accelerometer.

sps014 commented 2 years ago

Great will give pointers from now on. I will go from end.

mattleibow commented 2 years ago

I also know that @moljac is working on some too. Maybe he starts in the middle :)

moljac commented 2 years ago

Nope 'A'

now working on 'G'

moljac commented 2 years ago

@antonfirsov @sps014 I started with 'A' and am on 'G' right now. I didn't raise PRs because few of those are a bit tougher.

antonfirsov commented 2 years ago

@moljac then we just did duplicate work :) I opened a PR for Accelerometer in #4630 and also finished AppActions πŸ˜„

How to divide the work then? I can also grab something else.

moljac commented 2 years ago

This is my list WIP

essentials-interfaces-accelerometer
essentials-interfaces-appactions
essentials-interfaces-barometer
essentials-interfaces-battery
essentials-interfaces-browser
essentials-interfaces-clipboard
essentials-interfaces-compass
essentials-interfaces-connectivity
essentials-interfaces-email
essentials-interfaces-filepicker
essentials-interfaces-filesystem
m

currently preparing G

moljac commented 2 years ago

@moljac then we just did duplicate work :) I opened a PR for Accelerometer in #4630 and also finished AppActions πŸ˜„

How to divide the work then? I can also grab something else.

Trying to raise PR ASAP. As soon as builds are green.

Just pick some and put list here and it should be good for all of us to see what is up-for-grabs.

antonfirsov commented 2 years ago

Today I don't plan to start anything new. Won't PR AppActions, since it's duplicate work.

moljac commented 2 years ago

Today I don't plan to start anything new. Won't PR ApActions, since it's duplicate work.

I tried to update issue and/or push/raise all PRs and mark some as drafts, but I don't have ANY rights here (in this repo). πŸ˜„

Don't wory, I will continue working. Please, check here before continuing work, so we spare our precious time.

antonfirsov commented 2 years ago

@moljac I will pick some of the remaining items on Sunday or Monday. Let's say the stuff between Preferences - Share. Is it fine with you?

moljac commented 2 years ago

FYI started work on:

essentials-interfaces-hapticfeedback
essentials-interfaces-launcher
essentials-interfaces-magnetometer
essentials-interfaces-map
essentials-interfaces-mediapicker
essentials-interfaces-orientationsensor
antonfirsov commented 2 years ago

I will work on Screenshot .. Share today (& possibly more).

moljac commented 2 years ago

@Redth @mattleibow @rmarinho @jsuarezruiz

Hi

Here:

https://github.com/dotnet/maui/pull/4464/files#diff-2c429fd1e9c28a636e0af7b0d118980207e1412bbd0c75a08ea43a4b313ff4e8L31

and here:

https://github.com/dotnet/maui/pull/4466/files#diff-575ea05d8aa0835c4f48ef27c57b2cc678bd3608446df45597e5be8393da7c06L14

I saw removing Platform prefix, so I removed it in my PRs.

Now I have cyclic references Launcher is used by Browser, Email and PhoneDialer, so it will not build until those are merged OR I can make 1 PR with all 4 refactorings in that PR. Ideas? Wishes?

moljac commented 2 years ago

@antonfirsov Dobre rano!

Planning to start work on last 4 features:

essentials-interfaces-texttospeech
essentials-interfaces-versiontracking
essentials-interfaces-vibration
essentials-interfaces-webauthenticator

Is this OK with you?

How come you can edit this issue?

antonfirsov commented 2 years ago

Is this OK with you?

Yeah, I don't plan to push further PR-s for this one.

ow come you can edit this issue?

@Redth added me to maui-internal-contributors yesterday.

moljac commented 2 years ago

@Redth added me to maui-internal-contributors yesterday.

Say hello to him for me. MAUI is non-inclusive project πŸ˜„ At least now I have contact point, communication officer.

antonfirsov commented 2 years ago

@moljac pinged you on Teams. (If you use it ...)

moljac commented 2 years ago

Sorry for delays. Trying to answer questions about Maps v.18 and impact on Xamarin.Forms (in GPSA-FB-MLKit repo)

https://github.com/xamarin/GooglePlayServicesComponents/issues/562

antonfirsov commented 2 years ago

@moljac do you plan to continue working on this or should I take the remaining ones? If you can take it, I can deal with other important tasks, but it is very important to finish this refactor by EOW.

moljac commented 2 years ago

@moljac do you plan to continue working on this or should I take the remaining ones? If you can take it, I can deal with other important tasks, but it is very important to finish this refactor by EOW.

Which are remaining ones? I was busy trying to jumpstart CI builds for AndroidX, GooglePlayServices-Firebase-MLKit and XamarinComponents repo. Sorry. I see MAUI team was busy. Let me check what is left