-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
979 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#pragma once | ||
|
||
#include <CABasicAnimationPrototype.h> | ||
#include <CAMediaTimingFunction.h> | ||
#include <Timer.h> | ||
#include <string> | ||
#include <optional> | ||
|
||
namespace NXKit { | ||
|
||
class CAAction {}; | ||
|
||
class CABasicAnimation: public CAAction { | ||
public: | ||
/// animation duration in seconds | ||
double duration = 0; | ||
|
||
/// animation delay in seconds | ||
double delay = 0; | ||
|
||
std::optional<std::string> keyPath; | ||
std::optional<std::string> fillMode; | ||
bool isRemovedOnCompletion = true; | ||
std::shared_ptr<CAMediaTimingFunction> timingFunction; | ||
|
||
std::optional<AnimatableProperty> fromValue; | ||
std::optional<AnimatableProperty> toValue; | ||
|
||
std::shared_ptr<UIViewAnimationGroup> animationGroup; | ||
Timer creationTime; | ||
|
||
CABasicAnimation(std::string keyPath); | ||
CABasicAnimation(std::shared_ptr<CABasicAnimationPrototype> prototype, std::string keyPath, AnimatableProperty fromValue, std::shared_ptr<CAMediaTimingFunction> timingFunction); | ||
CABasicAnimation(CABasicAnimation* animation); | ||
|
||
bool wasCreatedInUIAnimateBlock(); | ||
float progressFor(Timer currentTime); | ||
|
||
private: | ||
float ease(float x); | ||
}; | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
|
||
#include <UIViewAnimationGroup.h> | ||
#include <tools/SharedBase.hpp> | ||
#include <memory> | ||
#include <any> | ||
|
||
namespace NXKit { | ||
|
||
using AnimatableProperty = std::any; | ||
|
||
class CABasicAnimation; | ||
class CABasicAnimationPrototype: public enable_shared_from_this<CABasicAnimationPrototype> { | ||
public: | ||
const double duration; | ||
const double delay; | ||
const std::shared_ptr<UIViewAnimationGroup> animationGroup; | ||
|
||
CABasicAnimationPrototype(double duration, double delay, std::shared_ptr<UIViewAnimationGroup> animationGroup); | ||
|
||
virtual std::shared_ptr<CABasicAnimation> createAnimation(std::string keyPath, AnimatableProperty fromValue); | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <memory> | ||
#include <functional> | ||
#include <UIViewAnimationOptions.h> | ||
|
||
namespace NXKit { | ||
|
||
// Note these are actually acceleration rates (explains why Fast is a smaller value than Normal) | ||
const double UIScrollViewDecelerationRateNormal = 0.998; | ||
const double UIScrollViewDecelerationRateFast = 0.99; | ||
|
||
const std::string kCAMediaTimingFunctionLinear = "linear"; | ||
const std::string kCAMediaTimingFunctionEaseIn = "easeIn"; | ||
const std::string kCAMediaTimingFunctionEaseOut = "easeOut"; | ||
const std::string kCAMediaTimingFunctionEaseInEaseOut = "easeInEaseOut"; | ||
const std::string kCAMediaTimingFunctionDefault = "default"; | ||
const std::string kCAMediaTimingFunctionCustomEaseOut = "customEaseOut"; | ||
const std::string kCAMediaTimingFunctionEaseOutElastic = "easeOutElastic"; | ||
|
||
class CAMediaTimingFunction { | ||
public: | ||
CAMediaTimingFunction(std::string name); | ||
CAMediaTimingFunction(std::function<double(double)> timing); | ||
|
||
static double linear(double x); | ||
static double easeInCubic(double x); | ||
static double easeOutCubic(double x); | ||
static double easeInQuad(double x); | ||
static double easeOutQuad(double x); | ||
static double easeInOutCubic(double x); | ||
static double easeOutElastic(double x); | ||
|
||
// from CubicBezier1D optimising away constant terms | ||
static double customEaseOut(double x); | ||
static std::shared_ptr<CAMediaTimingFunction> timingFunctionFrom(UIViewAnimationOptions options); | ||
|
||
float at(float x); | ||
private: | ||
std::function<double(double)> timing; | ||
}; | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
|
||
#include <CABasicAnimation.h> | ||
#include <CASpringAnimationPrototype.h> | ||
|
||
namespace NXKit { | ||
|
||
class CASpringAnimation: public CABasicAnimation { | ||
public: | ||
std::optional<double> damping; | ||
std::optional<double> initialSpringVelocity; | ||
|
||
CASpringAnimation(CASpringAnimation* animation); | ||
CASpringAnimation(std::shared_ptr<CASpringAnimationPrototype> prototype, | ||
std::string keyPath, | ||
AnimatableProperty fromValue); | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include <CABasicAnimationPrototype.h> | ||
|
||
namespace NXKit { | ||
|
||
class CASpringAnimation; | ||
class CASpringAnimationPrototype: public CABasicAnimationPrototype { | ||
public: | ||
const double damping; | ||
const double initialSpringVelocity; | ||
|
||
CASpringAnimationPrototype(double duration, | ||
double delay, | ||
double damping, | ||
double initialSpringVelocity, | ||
std::shared_ptr<UIViewAnimationGroup> animationGroup); | ||
|
||
std::shared_ptr<CABasicAnimation> createAnimation(std::string keyPath, AnimatableProperty fromValue) override; | ||
|
||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#include <CALayer.h> | ||
|
||
namespace NXKit { | ||
|
||
struct CATransaction { | ||
private: | ||
bool disableActions_ = false; | ||
float animationDuration_ = CALayer::defaultAnimationDuration; | ||
|
||
static std::vector<CATransaction> transactionStack; | ||
|
||
public: | ||
static void begin(); | ||
|
||
static void commit(); | ||
|
||
static bool disableActions(); | ||
|
||
static void setDisableActions(bool newValue); | ||
|
||
static float animationDuration(); | ||
|
||
static void setAnimationDuration(float newValue); | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.