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

[iOS] button.SetBackgroundImage(image, state) does not work #21265

Closed
kassemyu opened this issue Mar 18, 2024 · 7 comments
Closed

[iOS] button.SetBackgroundImage(image, state) does not work #21265

kassemyu opened this issue Mar 18, 2024 · 7 comments
Labels
area-controls-button Button, ImageButton custom-handler platform/iOS 🍎 s/needs-info Issue needs more info from the author s/triaged Issue has been reviewed t/bug Something isn't working

Comments

@kassemyu
Copy link

Description

Hey,

the button.SetBackgroundImage(image, state) seems to not work. Changing the background color works, which is unfortunately not sufficient because I need to show different backgrounds for different states. I saw that 8.0.6 had a fix for the ContentPage background in #17789 and a similar bug was resolved in nightly version for 8.0.0 in #12959 but somehow is still present according to the last comment of the thread. Are there any workarounds for this?

Thanks in advance!

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

8.0.6 SR1

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

@kassemyu kassemyu added the t/bug Something isn't working label Mar 18, 2024
@PureWeen
Copy link
Member

@kassemyu can you use the VSM that's built into .NET MAUI?

if you want to replace how .NET MAUI is handling background your best bet is to use mappers to replace how .NET MAUI is setting the background

https://learn.microsoft.com/en-us/dotnet/maui/user-interface/handlers/customize?view=net-maui-8.0

@PureWeen PureWeen added platform/iOS 🍎 s/needs-info Issue needs more info from the author custom-handler labels Mar 18, 2024
@kassemyu
Copy link
Author

@PureWeen thanks for your reply. I forgot to mention that I use handlers to design iOS and Android buttons (migration from renderers to handlers). I don't use visual state managers in this case. After writing this ticket I found a workaround with Mappers. When having a mapper for Button.IsPressed, the native button states "Normal" and "Highlighted" are triggered when the button is pressed. I change the background color respectively via:

handler.PlatformView.BackgroundColor = _backgroundColor;

Previously, I was using a rounded rectangle shape which is then colored and displayed as background via

button.SetBackgroundImage(image, state);

Other functions using the state such as

handler.PlatformView.SetTitleColor(_titleNormalColor, UIControlState.Normal);

work fine. The issue seems to be in the button.SetBackgroundImage.

@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Mar 18, 2024
@PureWeen
Copy link
Member

@kassemyu Do you think this is still a MAUI issue? or something specific to iOS?

Is this something you could test with a MAUI iOS app (not using our cross platform elements) see if that acts accordingly?

@PureWeen PureWeen added s/needs-info Issue needs more info from the author and removed s/needs-attention Issue has more information and needs another look labels Mar 19, 2024
@kassemyu
Copy link
Author

Hey @PureWeen, it was working on Xamarin that way so I suspect it to be a MAUI issue, I can't tell for sure unfortunately.

@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Mar 22, 2024
@Eilon Eilon added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Mar 28, 2024
@jaosnz-rep jaosnz-rep added the s/triaged Issue has been reviewed label May 7, 2024
@Eilon Eilon added area-controls-button Button, ImageButton and removed legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor labels May 11, 2024
@samhouts samhouts removed the s/triaged Issue has been reviewed label Jul 3, 2024
@samhouts samhouts added the s/triaged Issue has been reviewed label Jul 10, 2024
@mattleibow
Copy link
Member

Since you are overriding the background logic, you might just need to disable the mapper:

builder
  .ConfigureMauiHandlers(handlers =>
  {
    // do not map the background
    ButtonHandler.Mapper.ReplaceMapping("Background", (handler, view) => {
    });
  });

@mattleibow mattleibow added s/needs-info Issue needs more info from the author and removed s/needs-attention Issue has more information and needs another look labels Jul 24, 2024
Copy link
Contributor

Hi @kassemyu. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@dotnet-policy-service dotnet-policy-service bot added the s/no-recent-activity Issue has had no recent activity label Jul 29, 2024
Copy link
Contributor

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

@github-actions github-actions bot locked and limited conversation to collaborators Sep 1, 2024
@dotnet-policy-service dotnet-policy-service bot removed the s/no-recent-activity Issue has had no recent activity label Sep 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-button Button, ImageButton custom-handler platform/iOS 🍎 s/needs-info Issue needs more info from the author s/triaged Issue has been reviewed t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants