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

Entry tint color not works in iOS and MAC #13416

Closed
jeya-kasipandi opened this issue Feb 17, 2023 · 5 comments
Closed

Entry tint color not works in iOS and MAC #13416

jeya-kasipandi opened this issue Feb 17, 2023 · 5 comments
Labels
area-controls-entry Entry blocked Work that is currently blocked external platform/macOS 🍏 macOS / Mac Catalyst t/bug Something isn't working

Comments

@jeya-kasipandi
Copy link

jeya-kasipandi commented Feb 17, 2023

Description

Changed tint color in entry as like below code snippet by using handler in iOS and mac to change the text selection highlight color.But it does not work in mac and iOS platform.

private void Button_Clicked(object sender, EventArgs e)
{
#if MACCATALYST || IOS
if (entry.Handler.PlatformView is Microsoft.Maui.Platform.MauiTextField macEntry)
{
macEntry.TintColor = UIKit.UIColor.Green;
}
#endif

Steps to Reproduce

1.Run the sample from below link
https://github.com/jeya-kasipandi/Entry-selection-issue
2.Click button to change the entry selection color
3.Type the text and select the text
4.Selection color not changed to green color it show the default color in mac and iOS

Link to public reproduction project repository

https://github.com/jeya-kasipandi/Entry-selection-issue

Version with bug

6.0.312

Last version that worked well

Unknown/Other

Affected platforms

iOS, macOS

Affected platform versions

iOS 16.2,MAC

Did you find any workaround?

No response

Relevant log output

No response

@jeya-kasipandi jeya-kasipandi added the t/bug Something isn't working label Feb 17, 2023
@jeya-kasipandi
Copy link
Author

Can you share any workaround or solution to resolve this issue?

@jfversluis
Copy link
Member

It seems that entry.Handler is null at this point.

Change your code to be like this, and it works:

#if MACCATALYST || IOS
		Microsoft.Maui.Handlers.EntryHandler.Mapper.AppendToMapping("TintColor", (handler, entry) =>
		{
			handler.PlatformView.TintColor = UIKit.UIColor.Green;
		});
#endif

Additionally, if you don't want to make the TintColor green for all entries, you can create an inheritance of Entry and check for that in here as well. More information can be found in our documentation: https://learn.microsoft.com/dotnet/maui/user-interface/handlers/customize?view=net-maui-7.0

@jfversluis jfversluis closed this as not planned Won't fix, can't repro, duplicate, stale Feb 17, 2023
@jeya-kasipandi
Copy link
Author

Hi @jfversluis

As per your suggestion, I have set like below code snippet it works in iOS but it does not work in mac
C#:
void entry_HandlerChanged(System.Object sender, System.EventArgs e)   
 {        
 Entry entry = sender as Entry;
 #if MACCATALYST || IOS       
  (entry.Handler.PlatformView as UITextField).TintColor=UIColor.Green;
 #endif   
   }
   
   XAML
   <entry:CustomEntry HandlerChanged="entry_HandlerChanged" Text="Enter Text"      WidthRequest="250"/>
   
MicrosoftTeams-image (8)

MicrosoftTeams-image (7)

@jeya-kasipandi
Copy link
Author

Can you open this issue and provide solution or workaround?

@jfversluis
Copy link
Member

Seems like Apple just didn't implement this functionality for Mac Catalyst. You can do this:

#if MACCATALYST || IOS
		Microsoft.Maui.Handlers.EntryHandler.Mapper.AppendToMapping("TintColor", (handler, entry) =>
		{
#if IOS
			handler.PlatformView.TintColor = UIKit.UIColor.Green;
#elif MACCATALYST
			var textInputTraits = handler.PlatformView.ValueForKey((NSString)"textInputTraits");
			textInputTraits.SetValueForKey(UIColor.Red, (NSString)"insertionPointColor");
#endif

		});
#endif

But that will only color the cursor. I haven't found a way to also color the selection color, maybe it's just not possible. This is not a bug with .NET MAUI, this is just something that is not working/unclear how to do it in the Apple APIs.

@ghost ghost locked as resolved and limited conversation to collaborators Mar 19, 2023
@samhouts samhouts added platform/macOS 🍏 macOS / Mac Catalyst blocked Work that is currently blocked external labels May 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-entry Entry blocked Work that is currently blocked external platform/macOS 🍏 macOS / Mac Catalyst t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants