[Bug][iOS] TouchEffect does not work anymore, if compiled for iPhone|Release and Expander is also used
Description
xct:TouchEffect commands are no longer triggered when the Xamarin Forms project is compiled and deployed in iOS physical device release mode. This only occurs if the 'xct:Expander' view is also deployed somewhere in the app. Running the app compiled in Debug mode on the physical device the TouchEffect is okay. When compiling in 'iPhone Simulator' mode (Debug or Release behaves the same here), the TouchEffect is also okay.
Steps to Reproduce
- Create a single page Xamarin.Forms app with VisualStudio project template
- Add the XCT Nuget
- Add the TouchEffect on any view or layout and wire the command to a Page.DisplayAlert()
- Add xct:Expander anywhere in the page or in another page
- Compile for iOS | iPhone | Release and deploy it on a physical device
- The DisplayAlert is not shown
- Remove the xct:Expander and it works fine
Expected Behavior
The TouchEffect should execute the wired command.
Actual Behavior
The TouchEffect does not execute the command.
Basic Information
- Version with issue: 1.2.0
- Last known good version: None
- IDE: Visual Studio 2019 16.11.3, 16.11.2, 16.11.1
- Platform Target Frameworks:
- iOS: 14.5
- Nuget Packages: Xamarin.Forms (5.0.0.2012), Xamarin.CommunityToolkit (1.2.0)
- Affected Devices: only physical devices (i used iPad 8Gen with iOS 14.7.1 and iPad Pro 11" with iOS 14.7.1)
Additional Info
The same bug also happens with newest Xamarin.Forms (5.0.0.2083) and Xamarin.CommunityToolkit (1.3.0-pre2), but only when the app is more complex than the simple project template sample app that I attached. Because of that, updating is not a good workaround. Changing the 'release'-mode linking behaviour to 'Don't link' doesn't fix the bug Microsoft Doc
Reproduction project
Xamarin.Forms project template app with TouchEffect and Expander: Sample App XCTTest.zip
I think I have a similar issue.
I have a few Frames inside a StackLayout and they have the XCT Command and NativeAnimation properties set:
<Frame xct:TouchEffect.Command="{Binding SomeCommand}" xct:TouchEffect.NativeAnimation="True">
<!-- ... -->
</Frame>
On Android, it works just fine. On iOS, in Debug|iPhone config it works as well. However, in Release|iPhone config (IPA ad-hoc distribution), the commands are not executed...
I have only recently started testing the iOS app so I cannot say if this has always been the behavior or if it's indeed a new issue.
The nuget packages are Xamarin.ToolkitCommunity 1.2.0 and and Xamarin.Forms 5.0.0.2012. I have tested on iPhone 5s (iOS 12.x) and iPhone X (iOS 14.x).
Same here - for a touch effect frame this line is true so ShouldReceiveTouch is false:
if (recognizer.View is not IVisualNativeElementRenderer elementRenderer || elementRenderer.Control == null) return false;
I've currently fixed my forked repo with this:
public override bool ShouldReceiveTouch(UIGestureRecognizer recognizer, UITouch touch)
{
if (recognizer.View.IsDescendantOfView(touch.View))
return true;
if (recognizer.View is IVisualElementRenderer)
return true;
if (recognizer.View is not IVisualNativeElementRenderer elementRenderer ||
elementRenderer.Control == null)
return false;
if (elementRenderer.Control == touch.View ||
elementRenderer.Control.Subviews.Any(view => view == touch.View))
return true;
return false;
}
Not sure of the knock on effects yet.
Hey folks, could you please check the latest PRE-release version?
Still not working for iPhone|Release. Checked on 1.3.0-pre2
Hey folks, could you please check the latest PRE-release version?
Still not working in 1.3.0 release version. @ThomasAdrian - your fix worked great for me, thanks. Worth a PR?
My toucheffects also were not working in Ios release mode with version 1.3.0. Just upgraded to 1.3.1 which fixes it. Thanks!!!
Bummer, have to take that back. Made a release version for testing in Testflight, after two days waiting for approval: the toucheffects do not work anywhere in the app. No response.
Anyone have an idea why this works fine in Debug mode and not in Release mode on a device? I use the latest releases.
Edit: I do not use the expander like in the topic here btw. I do use some syncfusion controls though.
If you release a version with linker marked as Don't link, does it work?
Hi @pictos,
Yes that makes the difference!
I just did some testing with releasing to a device:
-
Linker Behaviour 'Link Framework SDK's only': Toucheffects DO NOT work
-
Linker Behaviour 'Dont' Link': : Toucheffects work
@Ed156 can you create a small repro and attach it here? That would help us to fix or find a workaround
I tried to reproduce it with a new app with one toucheffect but there it keeps working fine in release mode on the device.
Is there anything else I could try, or share?
@Ed156 If it's possible can you share the XAML code that you're using the effect?
On my end I tried with an added a subclass of some related ios code from the toolkit, in order to influence the linker, but this did not make a difference.
@Ed156 I believe that if you use the effect in code-behind the linker will keep the reference... XAML uses too much reflection and Linker doesn't handle that very well. You can also create a linkerpreserve.xml file and add the TouchEffect's namespace there. I hope that linker for .net 6 is better and more cleaver.
Thanks Pedro I will try that monday when I am near my remote build host to be able to put a release version on my test device.
Hi Pedro i tried to influence the linker by using the linkersettings.xml that was already present (for prism). But anything I tried there did not seem to work:
For example:
<assembly fullname="Xamarin.CommunityToolkit">
<namespace fullname="Xamarin.CommunityToolkit.iOS.Effects"/>
<namespace fullname="Xamarin.CommunityToolkit.Effects"/>
</assembly>
Or even on assembly level:
<assembly fullname="Xamarin.CommunityToolkit"/>
But I got it working in Release mode by using '--linkskip Xamarin.CommunityToolkit' as mtouch argument. I guess that is not ideal but at least i can now make a working release version.
This is still an issue. Had to use @Ed156's solution of adding --linkskip Xamarin.CommunityToolkit as mtouch argument. This happens even without Expander use.
I wonder does this issue only occur when referring to the effect in XAML. If you used it in C# would the compiler/linker still remove it?