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

Adding control size trigger #3867

Merged
14 commits merged into from
Aug 26, 2021

Conversation

dpaulino
Copy link
Contributor

@dpaulino dpaulino commented Mar 19, 2021

Fixes

Adding a new visual state trigger which can be triggered based on a the width of a UI element rather than the width of the app's entire window.

PR Type

What kind of change does this PR introduce?

Feature

What is the current behavior?

What is the new behavior?

PR Checklist

Please check if your PR fulfills the following requirements:

Other information

@ghost
Copy link

ghost commented Mar 19, 2021

Thanks dpaulino for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌

@ghost ghost requested review from michael-hawker, azchohfi and Kyaa-dost March 19, 2021 01:45
@net-foundation-cla
Copy link

net-foundation-cla bot commented Mar 19, 2021

CLA assistant check
All CLA requirements met.

@net-foundation-cla
Copy link

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

❌ dpaulino sign now
You have signed the CLA already but the status is still pending? Let us recheck it.

@ghost ghost requested a review from Rosuavio March 19, 2021 01:45
@michael-hawker
Copy link
Member

Thanks @dpaulino, I feel like we may have an issue somewhere open for this? I know it's been a long-standing 'to do' thing. 🙂

You can check-out the Wiki Page on Adding a Sample here too, we may also want to add tests for the triggers in our test suite.

@dpaulino
Copy link
Contributor Author

Thanks dpaulino, I feel like we may have an issue somewhere open for this? I know it's been a long-standing 'to do' thing. 🙂

You can check-out the Wiki Page on Adding a Sample here too, we may also want to add tests for the triggers in our test suite.

I took a glance at issues relating triggers but couldn't spot one. But I can try to look more carefully in a bit. Also, full credit goes to @rudyhuyn for creating this. With his permission, I merely volunteered to bring this to the toolkit.

I'll work on the other pr requirements over the next few days.

@michael-hawker
Copy link
Member

Cool, if it's @rudyhuyn's code, we should just get his buy-in on the PR even if it's just a comment saying he approves, it helps if he's signed the .NET Foundation CLA as well from the link above in the bot message.

@michael-hawker michael-hawker added this to the 7.1 milestone Mar 22, 2021
@michael-hawker
Copy link
Member

FYI there's also one in the platform samples apparently: https://github.com/microsoft/Windows-universal-samples/blob/master/Samples/XamlStateTriggers/cs/CustomTriggers/ControlSizeTrigger.cs

(Thanks @Arlodotexe for the link).

Do we want to worry about height too? Should it be combined or independent? Independent means you could have both triggers for the same state more easily, right?

@michael-hawker
Copy link
Member

@dpaulino thoughts on the height? We also need docs and a unit test would probably be good?

@michael-hawker michael-hawker mentioned this pull request May 25, 2021
27 tasks
@michael-hawker
Copy link
Member

@dpaulino did you want to compare the implementations still and work on a quick test and sample for this still?

@dpaulino
Copy link
Contributor Author

@michael-hawker hey sorry for the radio silence! I think having a separate controlHeightTrigger class may be preferred. Might be clearer in usage to see separate triggers for width and for height. Thoughts?

I'll try to make a sample for this soon, and yeah I can play around with the one from the official samples. If they perform similarly, what do you think is the best approach? Just c/p that code instead of using this one?

@michael-hawker
Copy link
Member

@dpaulino having them combined as a single trigger I think would be preferable; as if they're separate triggers, you can only do OR for width/height. By having them combined, you have use && in the trigger logic if the dev sets a width and height. Then if they want an OR they just setup two separate copies of the trigger (one with Width and one with Height). See doc for StateTriggers as it'll apply is any trigger is matched.

I like that yours has the min/max range style as well, so maybe a combination of both?

As for adding a sample, we have a wiki doc here, but there's a ton of existing StateTrigger samples, so you can just copy one of those too as a starting point.

@ghost
Copy link

ghost commented Aug 12, 2021

This PR has been marked as "needs attention 👋" and awaiting a response from the team.

@dpaulino dpaulino requested review from michael-hawker and removed request for Kyaa-dost August 15, 2021 01:51
@dpaulino
Copy link
Contributor Author

Oops sorry if I changed the reviewer! Not quite sure what happened!

@michael-hawker
Copy link
Member

@dpaulino missing the header on the new test file 😉

@ghost ghost removed the needs attention 👋 label Aug 16, 2021
@dotMorten
Copy link
Contributor

dotMorten commented Aug 16, 2021

Would it make more sense to make the default values NaN ?
It seems to me you need to set at least two parameters, but if all I want to do is trigger it when larger than a value (ie MinWidth/Height), I still need to set the Max values too. NaN could indicate "don't check".
Ie if I just want it to turn on when MinWidth > 300, I still have to set MaxWidth to Infinity or something else very large, or the expression would be false still.

@dpaulino
Copy link
Contributor Author

Would it make more sense to make the default values NaN ?
It seems to me you need to set at least two parameters, but if all I want to do is trigger it when larger than a value (ie MinWidth/Height), I still need to set the Max values too. NaN could indicate "don't check".
Ie if I just want it to turn on when MinWidth > 300, I still have to set MaxWidth to Infinity or something else very large, or the expression would be false still.

Yeah that makes sense. Let me make some changes

@dpaulino
Copy link
Contributor Author

@dotMorten the trigger now has double.NaN as default. Tests added as well to test the different scenarios. Thanks for the feedback.

@michael-hawker
Copy link
Member

From @dotMorten:

Ie if I just want it to turn on when MinWidth > 300, I still have to set MaxWidth to Infinity or something else very large, or the expression would be false still.

@dpaulino wasn't this the case already as the default was Infinity? I'm confused. You should just be able to set MaxWidth="300" and be done with the original code, right?

We're concerned about the extra complexity in all the extra logic when it should have just worked as is?

Also tests are failing in the CI:

 Failed ControlSizeTriggerTest [587 ms]
  Failed ControlSizeTriggerTest (450,450,True) [584 ms]
  Error Message:
   Assert.AreEqual failed. Expected:<True>. Actual:<False>. 
  Stack Trace:
     at UnitTests.UWP.UI.Triggers.Test_ControlSizeTrigger.<>c__DisplayClass0_0.<ControlSizeTriggerTest>b__0() + 0x11c
   at System.Action.Invoke() + 0x1d
   at Microsoft.Toolkit.Uwp.DispatcherQueueExtensions.<>c__DisplayClass1_0.<EnqueueAsync>b__1() + 0x20
--- End of stack trace from previous location where exception was thrown ---

@dotMorten
Copy link
Contributor

dotMorten commented Aug 17, 2021

@michael-hawker UGH I totally misread that. I could swear the default was 0.0 for the max values, but I know see I must have had way too tired eyes to do a code review 🤦‍♂️. Getting lasik next week. Perhaps that'll help...

@dpaulino
Copy link
Contributor Author

Ok sounds good, I'll revert the change and fix the unit tests.

@dpaulino dpaulino force-pushed the feature/control-width-trigger branch from 79fba6b to f458d51 Compare August 18, 2021 05:04
@dpaulino
Copy link
Contributor Author

I reverted the change and fixed the unit tests.

@dpaulino
Copy link
Contributor Author

@michael-hawker The unit tests are passing for me locally, but the CI is failing. Is there something else I'm missing?

@dpaulino
Copy link
Contributor Author

CI build test passing, yay!

@dpaulino
Copy link
Contributor Author

Anything else I can do?

@michael-hawker michael-hawker added next preview ✈️ Label for marking what we want to include in the next preview release for developers to try. for-review 📖 To evaluate and validate the Issues or PR labels Aug 25, 2021
@michael-hawker michael-hawker changed the title Adding control width trigger Adding control size trigger Aug 25, 2021
@ghost
Copy link

ghost commented Aug 26, 2021

Hello @michael-hawker!

Because this pull request has the auto merge :zap: label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit d9e8845 into CommunityToolkit:main Aug 26, 2021
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto merge ⚡ for-review 📖 To evaluate and validate the Issues or PR helpers ✋ next preview ✈️ Label for marking what we want to include in the next preview release for developers to try.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants