Skip to content

Commit 179f6f6

Browse files
authored
breaking(IReactChoreographer): Extract interface from ReactChoreographer. (microsoft#1773)
* Extract interface from ReactChoreographer. Another slim, incremental slice building up to the Interfaces PR.
1 parent 0216c24 commit 179f6f6

File tree

5 files changed

+59
-12
lines changed

5 files changed

+59
-12
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Portions derived from React Native:
3+
// Copyright (c) 2015-present, Facebook, Inc.
4+
// Licensed under the MIT License.
5+
6+
using System;
7+
8+
namespace ReactNative.Modules.Core
9+
{
10+
/// <summary>
11+
/// A simple action queue that allows us to control the order certain
12+
/// callbacks are executed within a given frame.
13+
/// </summary>
14+
public interface IReactChoreographer : IDisposable
15+
{
16+
/// <summary>
17+
/// For use by <see cref="UIManager.UIManagerModule"/>.
18+
/// </summary>
19+
event EventHandler<FrameEventArgs> DispatchUICallback;
20+
21+
/// <summary>
22+
/// For use by <see cref="Animated.NativeAnimatedModule"/>.
23+
/// </summary>
24+
event EventHandler<FrameEventArgs> NativeAnimatedCallback;
25+
26+
/// <summary>
27+
/// For events that make JavaScript do things.
28+
/// </summary>
29+
event EventHandler<FrameEventArgs> JavaScriptEventsCallback;
30+
31+
/// <summary>
32+
/// Event used to trigger the idle callback. Called after all UI work has been
33+
/// dispatched to JavaScript.
34+
/// </summary>
35+
event EventHandler<FrameEventArgs> IdleCallback;
36+
37+
/// <summary>
38+
/// Activate the callback for the given key.
39+
/// </summary>
40+
/// <param name="callbackKey">The callback key.</param>
41+
void ActivateCallback(string callbackKey);
42+
43+
/// <summary>
44+
/// Deactivate the callback for the given key.
45+
/// </summary>
46+
/// <param name="callbackKey">The callback key.</param>
47+
void DeactivateCallback(string callbackKey);
48+
}
49+
}

ReactWindows/ReactNative.Shared/Modules/Core/ReactChoreographer.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717

1818
namespace ReactNative.Modules.Core
1919
{
20-
/// <summary>
21-
/// A simple action queue that allows us to control the order certain
22-
/// callbacks are executed within a given frame.
23-
/// </summary>
24-
public class ReactChoreographer : IDisposable
20+
/// <inheritdoc />
21+
public class ReactChoreographer : IReactChoreographer
2522
{
2623
#if WINDOWS_UWP
2724
private const CoreDispatcherPriority ActivatePriority = CoreDispatcherPriority.High;
@@ -33,7 +30,7 @@ public class ReactChoreographer : IDisposable
3330
private const int InactiveFrameCount = 120;
3431

3532
private static readonly Stopwatch _stopwatch = Stopwatch.StartNew();
36-
private static ReactChoreographer s_instance;
33+
private static IReactChoreographer s_instance;
3734

3835
private readonly object _gate = new object();
3936
private readonly HashSet<string> _callbackKeys = new HashSet<string>();
@@ -87,7 +84,7 @@ private ReactChoreographer() { }
8784
/// <summary>
8885
/// The choreographer instance.
8986
/// </summary>
90-
public static ReactChoreographer Instance
87+
public static IReactChoreographer Instance
9188
{
9289
get
9390
{
@@ -104,7 +101,7 @@ public static ReactChoreographer Instance
104101
/// <summary>
105102
/// Factory for choreographer instances associated with non main-view dispatchers.
106103
/// </summary>
107-
public static ReactChoreographer CreateSecondaryInstance(CoreApplicationView view)
104+
public static IReactChoreographer CreateSecondaryInstance(CoreApplicationView view)
108105
{
109106
return new ReactChoreographer(view);
110107
}

ReactWindows/ReactNative.Shared/ReactNative.Shared.projitems

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
<Compile Include="$(MSBuildThisFileDirectory)Modules\Core\ExceptionsManagerModule.cs" />
125125
<Compile Include="$(MSBuildThisFileDirectory)Modules\Core\FrameEventArgs.cs" />
126126
<Compile Include="$(MSBuildThisFileDirectory)Modules\Core\IMutableFrameEventArgs.cs" />
127+
<Compile Include="$(MSBuildThisFileDirectory)Modules\Core\IReactChoreographer.cs" />
127128
<Compile Include="$(MSBuildThisFileDirectory)Modules\Core\JavaScriptException.cs" />
128129
<Compile Include="$(MSBuildThisFileDirectory)Modules\Core\JSTimers.cs" />
129130
<Compile Include="$(MSBuildThisFileDirectory)Modules\Core\RCTDeviceEventEmitter.cs" />
@@ -256,4 +257,4 @@
256257
<Compile Include="$(MSBuildThisFileDirectory)UIManager\ViewManagersPropCache.cs" />
257258
<Compile Include="$(MSBuildThisFileDirectory)Views\View\ReactViewManager.cs" />
258259
</ItemGroup>
259-
</Project>
260+
</Project>

ReactWindows/ReactNative.Shared/UIManager/UIViewOperationQueueInstance.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class UIViewOperationQueueInstance
3838

3939
private readonly NativeViewHierarchyManager _nativeViewHierarchyManager;
4040
private readonly ReactContext _reactContext;
41-
private readonly ReactChoreographer _reactChoreographer;
41+
private readonly IReactChoreographer _reactChoreographer;
4242

4343
private readonly IList<Action> _nonBatchedOperations = new List<Action>();
4444

@@ -55,7 +55,7 @@ public class UIViewOperationQueueInstance
5555
/// <param name="reactChoreographer">
5656
/// The choreographer associated with this instance.
5757
/// </param>
58-
public UIViewOperationQueueInstance(ReactContext reactContext, NativeViewHierarchyManager nativeViewHierarchyManager, ReactChoreographer reactChoreographer)
58+
public UIViewOperationQueueInstance(ReactContext reactContext, NativeViewHierarchyManager nativeViewHierarchyManager, IReactChoreographer reactChoreographer)
5959
{
6060
_nativeViewHierarchyManager = nativeViewHierarchyManager;
6161
_reactContext = reactContext;

ReactWindows/ReactNative/UIManager/UIViewOperationQueue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public void AddRootView(
123123
CoreApplicationView foundView = CoreApplication.Views.First(v => v.Dispatcher == rootViewDispatcher);
124124

125125
// Create new ReactChoreographer for this view/dispatcher. It will only be used for its DispatchUICallback services
126-
ReactChoreographer reactChoreographer = ReactChoreographer.CreateSecondaryInstance(foundView);
126+
var reactChoreographer = ReactChoreographer.CreateSecondaryInstance(foundView);
127127

128128
queueInfo = new QueueInstanceInfo()
129129
{

0 commit comments

Comments
 (0)