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

Add UIBlock Interface #1050

Merged
merged 11 commits into from Mar 9, 2017
2 changes: 1 addition & 1 deletion ReactWindows/ReactNative.Net46/ReactPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void OnResume(Action onBackPressed)
/// </summary>
public async Task DisposeAsync()
{
RootView?.RemoveHandler(Keyboard.KeyDownEvent, (KeyEventHandler) OnAcceleratorKeyActivated);
RootView?.RemoveHandler(Keyboard.KeyDownEvent, (KeyEventHandler)OnAcceleratorKeyActivated);

if (_reactInstanceManager.IsValueCreated)
{
Expand Down
12 changes: 11 additions & 1 deletion ReactWindows/ReactNative.Net46/UIManager/UIManagerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,17 @@ public int AddMeasuredRootView(SizeMonitoringCanvas rootView)
return tag;
}

#region React Methods
/// <summary>
/// Schedule a block to be executed on the UI thread. Useful if you need to execute
/// view logic after all currently queued view updates have completed.
/// </summary>
/// <param name="block">The UI block.</param>
public void AddUIBlock(IUIBlock block)
{
_uiImplementation.AddUIBlock(block);
}

#region React Methods

/// <summary>
/// Removes the root view.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
<Compile Include="$(MSBuildThisFileDirectory)UIManager\BorderedViewParentManager.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UIManager\BorderExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UIManager\ColorHelpers.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UIManager\IUIBlock.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UIManager\ReactShadowNodeExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UIManager\ReactShadowNodeVisitor.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UIManager\DependencyObjectExtensions.cs" />
Expand Down
17 changes: 17 additions & 0 deletions ReactWindows/ReactNative.Shared/UIManager/IUIBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using ReactNative.UIManager;

namespace ReactNative.UIManager
{
/// <summary>
/// Interface that represents a block to execute on the UI thread.
/// Exposes NativeViewHierarchyManager for third party libraries.
/// </summary>
public interface IUIBlock
{
/// <summary>
/// Executes the block.
/// </summary>
/// <param name="nativeViewHierarchyManager">The native view hierarchy manager.</param>
void Execute(NativeViewHierarchyManager nativeViewHierarchyManager);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,11 @@ public void ShowPopupMenu(int tag, string[] items, ICallback success)
throw new NotImplementedException();
}

private DependencyObject ResolveView(int tag)
/// <summary>
/// Resolves a view.
/// </summary>
/// <param name="tag">The tag of the view.</param>
public DependencyObject ResolveView(int tag)
{
var view = default(DependencyObject);
if (!_tagsToViews.TryGetValue(tag, out view))
Expand All @@ -587,7 +591,11 @@ private DependencyObject ResolveView(int tag)
return view;
}

private IViewManager ResolveViewManager(int tag)
/// <summary>
/// Resolves a view's view manager.
/// </summary>
/// <param name="tag">The tag of the view.</param>
public IViewManager ResolveViewManager(int tag)
{
var viewManager = default(IViewManager);
if (!_tagsToViewManagers.TryGetValue(tag, out viewManager))
Expand Down
9 changes: 9 additions & 0 deletions ReactWindows/ReactNative.Shared/UIManager/UIImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,15 @@ public void ShowPopupMenu(int reactTag, string[] items, ICallback error, ICallba
_operationsQueue.EnqueueShowPopupMenu(reactTag, items, error, success);
}

/// <summary>
/// Enqueues UIBlock to be executed.
/// </summary>
/// <param name="block">The UI block.</param>
public void AddUIBlock(IUIBlock block)
{
_operationsQueue.EnqueueUIBlock(block);
}

/// <summary>
/// Called when the host receives the suspend event.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ public void EnqueueShowPopupMenu(int tag, string[] items, ICallback error, ICall
EnqueueOperation(() => _nativeViewHierarchyManager.ShowPopupMenu(tag, items, success));
}

/// <summary>
/// Enqueues a operation to execute a UIBlock.
/// </summary>
/// <param name="block">The UI block.</param>
public void EnqueueUIBlock(IUIBlock block)
{
EnqueueOperation(() => block.Execute(_nativeViewHierarchyManager));
}

/// <summary>
/// Enqueues an operation to create a view.
/// </summary>
Expand Down
12 changes: 11 additions & 1 deletion ReactWindows/ReactNative/UIManager/UIManagerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,17 @@ public int AddMeasuredRootView(SizeMonitoringCanvas rootView)
return tag;
}

#region React Methods
/// <summary>
/// Schedule a block to be executed on the UI thread. Useful if you need to execute
/// view logic after all currently queued view updates have completed.
/// </summary>
/// <param name="block">The UI block.</param>
public void AddUIBlock(IUIBlock block)
{
_uiImplementation.AddUIBlock(block);
}

#region React Methods

/// <summary>
/// Removes the root view.
Expand Down