cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Custom Easing Equations in Components (Custom Functions)

We are all aware of the ability in PowerApps to visually transform objects using the Timer control. This gives us the functionality of animations, elevating the visual appeal of solutions. But we have also seen how this can be improved.

 

In the June of 2018 @Mr-Dang-MSFT posted his helpful and insightful video on the use of Easing Equations in PowerApps animations. In it, he describes how motion in PowerApps animations can be made smooth by use of Easing Equations. These allow you to change linear motion into much more dynamic and sweeping movements. I'll leave the video linked below, along with a very helpful article I discovered going into a bit more detail:

 

https://powerusers.microsoft.com/t5/Webinars-and-Video-Gallery/Friday-Functions-Smoother-Animations-...

 

http://powerappsguide.com/blog/post/controls-how-to-show-hide-controls-with-a-sliding-transition-eff...

 

I won't go over again how to put animation into your apps, as Mr Dang does it perfectly, but I think it helpful to describe that Easing Equations, at a basic level, allow you to move, or transform, your object by fractions of it's size, position, or transparency. It does this at different rates over the duration of your Timer. This can be best described by a graph, and Mr Dang helpfully provided a site to show the various types of Easing: 

 

https://easings.net/

 

You can see in here the various paths of the graphs, and by hovering over them, the arrow to the right will display the expected movement when the equation is applied to your object. Wonderful! But there were a fair few of these, and many more options on how we might want to visually transform our object. And while we are provided with the breakdown of how these Easings are made using CSS or Post CSS, as well as the base maths function that we can use to transpose these into PowerApps, I myself was, and am not built for this level of complexity. How on earth would I get this:

 

 

function easeOutBack(x: number): number {
const c1 = 1.70158;
const c3 = c1 + 1;

return 1 + c3 * Math.pow(x - 1, 3) + c1 * Math.pow(x - 1, 2);
}

 

 

into PowerApps?

 

I had no idea. Maths was never my strong suit, and these honestly scared me. But I did know that functions like EaseOutBack, where, for example, your object may move out, overshoot, then settle back into the final position, felt a bit more advanced and professional than what I was already using. Then again, maths. Complicated maths. I was stuck.

 

But while I'm not a mathematician, I do happen to be incredibly, infuriatingly, undeniably, stubborn.

 

After days of looking around dark corners of the web, I stumbled onto this very helpful site by the name of SpicyYoghurt (what a name!): https://spicyyoghurt.com/tools/easing-functions

 

SpicyYoghurt goes into detail on how the same Easings can be constructed in JavaScript. Darn it. Buuuuut, this made a bit more sense to me. Maybe days of looking at maths had imprinted on me, or passed into my brain via osmosis.  

 

For EaseOutBack, SpicyYoghurt described that EaseOutBack could be expressed in JS as:

 

 

function easeOutBack (t, b, c, d) {
    if (s == undefined) s = 1.70158;
    return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
}

 

 

 

In this, the parameters are:

t = The current time value

b = The starting value (starting X value)

c = The change value (how far we want the item to move)

d = The duration

 

It turns out that pretty much all Easing equations use this parameters, as well as some mathematically defined constant that helps scale the equation depending on, for example, the size of the object being moved. And looking at these, my brain immediately thought "VARIABLES!". And then it went "BUT HOW DO WE USE THESE IN AN ACTUAL X PROPERTY?" (It was feeling quite shouty that day). Well, if I wanted to move a box, I could change the parameters in my head so that they actually read this:

 

t = The current value of the timer

b = The starting X coordinate

c = How far we want the item to move

d = The duration of timer

 

That made sense to me. Putting that equation into the X property was a different story. Was I meant to just paste the equation into the property, and replace the parameters with defined variables? It seemed clunky. And my mind couldn't wrap around how such an equation would actually interact with the property. 

 

But! Luckily, at this moment, I stumbled upon something talking about Custom Functions in PowerApps. Matthew Devaney's blog on all things PowerApps had posted on how to create Custom Functions. In it he was describing how to create reusable code for recreating Excel's EOMonth function:

https://www.matthewdevaney.com/power-apps-custom-functions-reusable-code/

 

Now, one thing I had never consciously considered, but understood instinctively, was that a function is basically a series of parameters that feed into a equation sitting in the background. So when I saw Matthew Devaney's guide, I thought that I might just be able to use the same method for my Easing equations. The Custom Functions needed to be enabled by activating Enhanced Component Properties in the Experimental Features, but after that I could use the JS example from SpicyYoghurt and get underway.

 

First, I made a new property called EaseOutBack by making a new Component, then selecting New Custom Property on the right:

EpicTriffid_1-1691502355207.png

 

Naming it EaseOutBack, I changed the Property Type to Function, Property Definition to Output, and Data type to Text.

EpicTriffid_2-1691502446170.png

Now I needed to add a new Parameter using the button at the bottom:

EpicTriffid_3-1691502510565.png

These were going to be the parameters in my Custom Function. Using the list of variables needed for the JS version of EaseOutBack above as a template for the data we need to gather, I entered a Parameter name, chose Data type Text, and then Saved, until all the below parameters had been made:

EpicTriffid_4-1691502654282.png

These were my 4 parameters. Now to create my formula. I pressed where it said the Property name on the right to open the formula bar at the top with our custom property already selected:

EpicTriffid_5-1691502775693.png

 

I now had to convert the JS formula to something that matched PowerApps syntax and my new parameters:

 

ChangeValue * ((TimerValue/Duration - 1) * TimerValue * ((1.70158 + 1) * TimerValue + 1.70158) + 1) + StartCoord

 

EpicTriffid_6-1691502868172.png

 

And that was it! Done! I made a custom function! I had no idea if it would work, but the journey had been long, and all I wanted to know what whether it looked any good. I headed back to my test screen, then selected Insert > Custom > EaseOutBack:

EpicTriffid_7-1691502976269.png

(I've made a few now, but you can see EaseOutBack in there.)

(When added, it'll appear as a fairly large but transparent box, like below, but I just shrink it to nothing and hide it:)

 

And now we can use it . In my case, I was going to have a box come in from the right of the screen, overshoot, then settle on the edge. I'd already made my box, so heading to its x property, I tried out my new function with the four new parameters:

 

 

If(
    flyOut,
    EaseOutBack_2.EaseOutBack((MenuTimer_1.Value/MenuTimer_1.Duration) - 1, -Self.Width, Self.Width, MenuTimer_1.Duration),
    EaseOutBack_2.EaseOutBack(((MenuTimer_1.Value/MenuTimer_1.Duration) - 1), Self.Width - Self.Width, -Self.Width, MenuTimer_1.Duration))

 

 

So now, using this, starting my position off the screen, then moving in by the width of the box, I got this:

 

Presentation4.gif

 

It worked! It might not seem like a lot, but I now had not only managed to use more than just the basic Easing Equation, but I had also made a process for making any number of different kinds of easing equations in components that could be moved wherever I wanted them. I can now use this repeatedly in my app, move it to another app, etc. I have already made versions of these to replace the SinIn and SinOut Easing Equations that Mr Dang created, so I hope to have more fun with this in the future. It was certainly empowering to create a final process all of my own design from several different sources and beginnings. I can now use this same functionality to create smooth and professional looking animations like below:

 

animation.gif

 

Hopefully this can be a useful resource for someone who is looking for something like this in the future, and that it is one of the results that actually shows up in a search engine! 🙂 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Solution in original post

View solution in original post

4 REPLIES 4

Nice write up, you should leave a comment on this, something like 

Solution in original post

then mark it as the solution so anyone looking for stuff like this will find your post quicker

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!

Thanks! Will do!

Solution in original post

JB006
Frequent Visitor

Thanks for sharing your thoughts, very helpful.

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!   This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions in the Forums to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber of SolutionsSuper UsersNumber of Solutions @anandm08  23 @WarrenBelz  31 @DBO_DV  10 @Amik  19 AmínAA 6 @mmbr1606  12 @rzuber  4 @happyume  7 @Giraldoj  3@ANB 6 (tie)   @SpongYe  6 (tie)     Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersSolutionsSuper UsersSolutions @anandm08  10@WarrenBelz 25 @DBO_DV  6@mmbr1606 14 @AmínAA 4 @Amik  12 @royg  3 @ANB  10 @AllanDeCastro  2 @SunilPashikanti  5 @Michaelfp  2 @FLMike  5 @eduardo_izzo  2   Meekou 2   @rzuber  2   @Velegandla  2     @PowerPlatform-P  2   @Micaiah  2     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 3:Community MembersSolutionsSuper UsersSolutionsPower Apps anandm0861WarrenBelz86DBO_DV25Amik66Michaelfp13mmbr160647Giraldoj13FLMike31AmínAA13SpongYe27     Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 4:Community MembersSolutionsSuper UsersSolutionsPower Apps DBO-DV21WarranBelz26Giraldoj7mmbr160618Muzammmil_0695067Amik14samfawzi_acml6FLMike12tzuber6ANB8   SunilPashikanti8

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (794)