Skip to content

Commit 23bc50c

Browse files
committed
Changes/Fixes from Erics recent code review
1 parent 697de67 commit 23bc50c

22 files changed

+204
-337
lines changed

ReactAndroid/src/main/java/com/facebook/react/animation/AnimationRegistry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class AnimationRegistry {
2222
private final SparseArray<Animation> mRegistry = new SparseArray<Animation>();
2323

2424
public void registerAnimation(Animation animation) {
25-
UiThreadUtil.assertOnUiThread();
25+
UiThreadUtil.assertOnUiThread();
2626
mRegistry.put(animation.getAnimationID(), animation);
2727
}
2828

@@ -40,4 +40,4 @@ public Animation removeAnimation(int animationID) {
4040
return animation;
4141
}
4242

43-
}
43+
}

ReactWindows/ReactNative.Tests/UIManager/LayoutAnimation/LayoutAnimationManagerTests.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
22
using Newtonsoft.Json.Linq;
33
using ReactNative.UIManager.LayoutAnimation;
4-
using System;
5-
using System.Collections.Generic;
6-
using System.Linq;
7-
using System.Text;
8-
using System.Threading.Tasks;
94

105
namespace ReactNative.Tests.UIManager.LayoutAnimation
116
{
@@ -24,7 +19,7 @@ public void LayoutAnimationManager_InvokeTests()
2419

2520
layoutAnimator.InitializeFromConfig(config);
2621

27-
Assert.AreEqual(layoutAnimator.Storyboard(AnimationState.create).PropertyType, AnimatedPropertyType.scaleXY);
22+
Assert.AreEqual(layoutAnimator.Storyboard(AnimationState.Create).PropertyType, AnimatedPropertyType.ScaleXY);
2823
}
2924
}
3025
}

ReactWindows/ReactNative/Animation/AnimationManager.cs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ public AnimationManager(int animationID, IAnimationPropertyUpdater propertyUpdat
1919

2020
public IAnimationListener AnimationListener{ get; set; }
2121

22-
protected FrameworkElement View { get; private set; }
23-
24-
private bool Cancelled { get; set; }
25-
26-
private bool Finished { get; set; }
27-
2822
public int AnimationId { get; set; }
2923

3024
public abstract void Run();
@@ -36,6 +30,24 @@ public void Start(FrameworkElement view)
3630
Run();
3731
}
3832

33+
/// <summary>
34+
/// Cancels the animation.
35+
/// </summary>
36+
public void Cancel()
37+
{
38+
if (Finished || Cancelled)
39+
{
40+
// If we were already finished, ignore
41+
return;
42+
}
43+
44+
Cancelled = true;
45+
if (AnimationListener != null)
46+
{
47+
AnimationListener.OnCancel();
48+
}
49+
}
50+
3951
/// <summary>
4052
/// Animation engine should call this method for every animation frame passing animation progress
4153
/// value as a parameter. Animation progress should be within the range 0..1 (the exception here
@@ -46,6 +58,10 @@ public void Start(FrameworkElement view)
4658
/// </summary>
4759
/// <param name="value"></param>
4860
/// <returns></returns>
61+
62+
63+
protected FrameworkElement View { get; private set; }
64+
4965
protected bool OnUpdate(float value)
5066
{
5167
if (!Cancelled && View != null)
@@ -75,27 +91,13 @@ protected void Finish()
7591
}
7692
if (AnimationListener != null)
7793
{
78-
AnimationListener.onFinished();
94+
AnimationListener.OnFinished();
7995
}
8096
}
8197
}
8298

83-
/// <summary>
84-
/// Cancels the animation.
85-
/// </summary>
86-
public void Cancel()
87-
{
88-
if (Finished || Cancelled)
89-
{
90-
// If we were already finished, ignore
91-
return;
92-
}
99+
private bool Cancelled { get; set; }
93100

94-
Cancelled = true;
95-
if (AnimationListener != null)
96-
{
97-
AnimationListener.OnCancel();
98-
}
99-
}
101+
private bool Finished { get; set; }
100102
}
101103
}

ReactWindows/ReactNative/Animation/AnimationRegistry.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ namespace ReactNative.Animation
88
/// </summary>
99
public class AnimationRegistry
1010
{
11-
private readonly IDictionary<int, AnimationManager> _AnimationRegistry;
11+
private readonly IDictionary<int, AnimationManager> _animationRegistry;
1212

1313
public AnimationRegistry() { }
1414

1515
public AnimationRegistry(AnimationManager animation)
1616
{
1717
DispatcherHelpers.AssertOnDispatcher();
1818

19-
_AnimationRegistry = new Dictionary<int, AnimationManager>() {
19+
_animationRegistry = new Dictionary<int, AnimationManager>() {
2020
{ animation.AnimationId, animation}
2121
};
2222
}
@@ -26,7 +26,7 @@ public AnimationManager GetAnimation(int animationID)
2626
DispatcherHelpers.AssertOnDispatcher();
2727
var animation = default(AnimationManager);
2828

29-
if (_AnimationRegistry.TryGetValue(animationID, out animation))
29+
if (_animationRegistry.TryGetValue(animationID, out animation))
3030
{
3131
return animation;
3232
}
@@ -40,7 +40,7 @@ public void RegisterAnimation(AnimationManager animation)
4040
{
4141
DispatcherHelpers.AssertOnDispatcher();
4242

43-
_AnimationRegistry[animation.AnimationId] = animation;
43+
_animationRegistry[animation.AnimationId] = animation;
4444
}
4545

4646
public AnimationManager RemoveAnimation(int animationID)
@@ -49,9 +49,9 @@ public AnimationManager RemoveAnimation(int animationID)
4949

5050
var animation = default(AnimationManager);
5151

52-
if (_AnimationRegistry.TryGetValue(animationID, out animation))
52+
if (_animationRegistry.TryGetValue(animationID, out animation))
5353
{
54-
_AnimationRegistry.Remove(animationID);
54+
_animationRegistry.Remove(animationID);
5555
}
5656

5757
return animation;

ReactWindows/ReactNative/Animation/IAnimationListener.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ namespace ReactNative.Animation
88
{
99
/// <summary>
1010
/// Interface for getting animation lifecycle updates. It is guaranteed that for a given animation,
11-
/// only one of <see cref="onFinished"/> and <see cref="OnCancel"/> will be called, and it will be called exactly once.
11+
/// only one of <see cref="OnFinished"/> and <see cref="OnCancel"/> will be called, and it will be called exactly once.
1212
/// </summary>
1313
public interface IAnimationListener
1414
{
1515
/// <summary>
16-
/// Called once animation is finished.
16+
/// Called once animation has finished.
1717
/// </summary>
18-
void onFinished();
18+
void OnFinished();
1919

2020
/// <summary>
2121
/// Called in case when animation was cancelled.

ReactWindows/ReactNative/Animation/IAnimationPropertyUpdater.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ public interface IAnimationPropertyUpdater
1717
/// <summary>
1818
/// This method will be called before animation starts.
1919
/// </summary>
20-
/// <param name="view">view that will be animated</param>
20+
/// <param name="view">View that will be animated.</param>
2121
void Prepare(FrameworkElement view);
2222

2323
/// <summary>
2424
/// This method will be called for each animation frame.
2525
/// </summary>
26-
/// <param name="view">view to update property</param>
27-
/// <param name="progress">animation progress from 0..1 range retrieved from <see cref="AnimationManager"/> engine.</param>
26+
/// <param name="view">View to update property.</param>
27+
/// <param name="progress">Animation progress from 0..1 range retrieved from <see cref="AnimationManager"/> engine.</param>
2828
void OnUpdate(FrameworkElement view, float progress);
2929

3030
/// <summary>
3131
/// This method will be called at the end of animation. It should be used to set the final values
3232
/// or animated properties in order to avoid floating point inacurracy calculated in <see cref="OnUpdate(FrameworkElement, float)"/>
3333
/// by passing value close to 1.0 or in a case some frames got dropped.
3434
/// </summary>
35-
/// <param name="view">view to update property</param>
35+
/// <param name="view">View to update property.</param>
3636
void onFinish(FrameworkElement view);
3737
}
3838
}

ReactWindows/ReactNative/ReactNative.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@
246246
<Compile Include="UIManager\Events\TouchEventType.cs" />
247247
<Compile Include="UIManager\Events\TouchEventTypeExtensions.cs" />
248248
<Compile Include="UIManager\LayoutAnimation\AnimationState.cs" />
249+
<Compile Include="UIManager\LayoutAnimation\InterpolationTypesExtensions.cs" />
249250
<Compile Include="UIManager\LayoutAnimation\StoryboardAnimation.cs" />
250251
<Compile Include="UIManager\LayoutAnimation\AnimatedPropertyType.cs" />
251252
<Compile Include="UIManager\LayoutAnimation\LayoutCreateAnimation.cs" />
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
1+

72
namespace ReactNative.UIManager.LayoutAnimation
83
{
4+
/// <summary>
5+
/// The enum types to indicate the type of animation that needs to be invoked for the LayoutAnimation API.
6+
/// </summary>
97
public enum AnimatedPropertyType
108
{
11-
opacity,
12-
scaleXY,
13-
None
9+
None,
10+
Opacity,
11+
ScaleXY,
1412
}
1513
}
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
1+

72
namespace ReactNative.UIManager.LayoutAnimation
83
{
94
public enum AnimationState
105
{
11-
create,
12-
update
6+
Create,
7+
Update
138
}
149
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using ReactNative.Views.Image;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using Windows.UI.Xaml.Media.Animation;
8+
9+
namespace ReactNative.UIManager.LayoutAnimation
10+
{
11+
static class InterpolationTypesExtensions
12+
{
13+
private static IReadOnlyDictionary<InterpolationType, EasingFunctionBase> EasingFunctions
14+
{
15+
get
16+
{
17+
return new Dictionary<InterpolationType, EasingFunctionBase>() {
18+
{ InterpolationType.EaseIn, new BackEase() { EasingMode = EasingMode.EaseIn, Amplitude = .5 } },
19+
{ InterpolationType.EaseOut, new BackEase() { EasingMode = EasingMode.EaseOut, Amplitude = .5} },
20+
{ InterpolationType.EaseInEaseOut, new BackEase() { EasingMode = EasingMode.EaseInOut, Amplitude = .5} },
21+
{ InterpolationType.Linear, null },
22+
{ InterpolationType.Spring, new ElasticEase() { Oscillations = 3 } }
23+
};
24+
}
25+
}
26+
27+
/// <summary>
28+
/// Determines the <see cref="EasingFunctionBase"/> of the <see cref="Storyboard"/>.
29+
/// </summary>
30+
public static EasingFunctionBase EasingFunction(this InterpolationType typeInstance)
31+
{
32+
var transitionFunction = default(EasingFunctionBase);
33+
34+
if (EasingFunctions.TryGetValue(typeInstance, out transitionFunction))
35+
{
36+
return transitionFunction;
37+
}
38+
else
39+
{
40+
return null;
41+
}
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)