[Bug] Fix RenderWith on Android so it properly links out renderers and native components
#7497 aperta il 12 set 2019
Metriche repository
- Star
- (5644 stelle)
- Metriche merge PR
- (Nessuna PR mergiata in 30 g)
Descrizione
Description
The initial intention of the RenderWith attributes were to create a loose coupling from the Xamarin Forms Core components to the Native components. This currently does not work on Android because of two factors
Original RenderWith ticket https://github.com/xamarin/Duplo/pull/2077
-
Assembly level Preserve Attributes need to be removed
-
Can we remove them? https://github.com/xamarin/Duplo/issues/347
-
Once the Preserve Attribute is removed we will need to work on including a set of linker hints with our platform project so that developers don't have to worry about figuring out how to make Forms linkable
-
-
The reference to the Renderer as a part of an attribute Parameter https://github.com/xamarin/Xamarin.Forms/blob/master/Stubs/Xamarin.Forms.Platform.cs#L51
- https://xamarinhq.slack.com/archives/C03CEGRUW/p1567605092112000
- https://github.com/mono/linker/blob/master/src/linker/Linker.Steps/MarkStep.cs#L749
- https://github.com/mono/linker/blob/master/src/linker/Linker.Steps/MarkStep.cs#L767
- So we will need to work with the Linker to change this behavior or change the RenderWith to possibly take a string or similar
-
Possible Alternative solution
- We could just get rid this concept working via Attributes and instead use a compile time step to generate code based Renderer registrations based on what components are being used. If the compiler misses something or the users need to use reflection they could create references the cross platform element as a compiler hint or similar so that we are able to trigger
- We determine that we just can't do this and we have to keep linking enable at which point we should just remove our internal use of RenderWIth and leave it for 3rd party libraries to use. at which point we should make it so that we don't scan for the RenderWith attribute by default to save on startup time
Work to be done before going full in on this
We should measure the value of doing this work. For a spike we could just delete all the RenderWith attributes and all the manual registration inside FormsAppCompat. This would effectively give us an idea of what nothing looks like. Once we have a measure of how much nothing differs from everything then we can see if it's worth the effort here.
From the Android team: If adding linking gets shrinks the overall apk by about 1 MB it'd probably be worth it
Testing
We will need to ensure that our UI tests all run with linking turned fully on so that we can catch any linking issues we need to package up with the application
What about iOS?
Currently iOS won't link anything out that inherits from NSObject so it's not (AFAIK) possible to link anything out of iOS