Skip to content

Commit

Permalink
Added rendering capability for a WPF Panel in React Native via a Reac…
Browse files Browse the repository at this point in the history
…tViewManager
  • Loading branch information
erikschlegel committed Jan 2, 2016
1 parent 3701804 commit cc26462
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace ReactNative.Tests
[TestClass]
public class ReactInstanceManagerTests
{
[TestMethod]
//TODO: Looking into XAML custom control issue. This test is currently being ignored for the meantime until the issue has been resolved.
public async Task ReactInstanceManagerInitializationSuccess()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public class ViewManagersPropertyCacheTests
public void ViewManagersPropertyCache_ArgumentChecks()
{
AssertEx.Throws<ArgumentNullException>(
() => ViewManagersPropertyCache.GetNativePropertiesForView(null,
(object)),
() => ViewManagersPropertyCache.GetNativePropertiesForView(null, typeof(object)),
ex => Assert.AreEqual("viewManagerType", ex.ParamName));

AssertEx.Throws<ArgumentNullException>(
Expand Down Expand Up @@ -53,7 +52,7 @@ public void ViewManagersPropertyCache_ViewManager_Set()

var setters = ViewManagersPropertyCache.GetNativePropertySettersForViewManagerType(typeof(ViewManagerValueTest));
Assert.AreEqual(3, setters.Count);

var properties = new CatalystStylesDiffMap(new JObject
{
{ "Foo", "v1" },
Expand Down Expand Up @@ -462,4 +461,4 @@ protected override FrameworkElement CreateViewInstance(ThemedReactContext reactC
#endregion
}
}
}
}
1 change: 1 addition & 0 deletions ReactWindows/ReactNative/ReactNative.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
<Compile Include="UIManager\Events\TouchEventTypeExtensions.cs" />
<Compile Include="UIManager\ReactPointerEventsView.cs" />
<Compile Include="UIManager\RootViewHelper.cs" />
<Compile Include="UIManager\RootViewManager.cs" />
<Compile Include="UIManager\TouchTargetHelper.cs" />
<Compile Include="UIManager\FrameworkElementExtensions.cs" />
<Compile Include="UIManager\ICatalystInterceptingViewGroup.cs" />
Expand Down
34 changes: 34 additions & 0 deletions ReactWindows/ReactNative/UIManager/RootViewManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace ReactNative.UIManager
{
class RootViewManager : ViewGroupManager
{
private readonly string REACT_CLASS = "ReactView";


/// <summary>
/// Get the name of the react root view
/// </summary>
public override string Name
{
get
{
return REACT_CLASS;
}
}

/// <summary>
/// Creates a new view instance of type <typeparamref name="Panel"/>.
/// </summary>
/// <param name="reactContext">The react context.</param>
/// <returns>The view instance.</returns>
protected override FrameworkElement CreateViewInstance(ThemedReactContext reactContext)
{
return new SizeMonitoringFrameLayout();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ protected sealed override FrameworkElement CreateViewInstance(ThemedReactContext
protected abstract TPanel CreateViewInstanceCore(ThemedReactContext reactContext);

/// <summary>
<<<<<<< 52b8b626cebd2f4762bc931bf5976f9f958d86ca
=======
/// This method should return the subclass of <see cref="ReactShadowNode"/>
/// which will be then used for measuring the position and size of the
/// view.
Expand All @@ -117,7 +115,6 @@ protected virtual LayoutShadowNode CreateShadowNodeInstanceCore()
}

/// <summary>
>>>>>>> Adding ReactViewManager
/// Callback that will be triggered after all properties are updated in
/// the current update transation (all <see cref="ReactPropertyAttribute"/> handlers
/// for properties updated in the current transaction have been called).
Expand Down
30 changes: 30 additions & 0 deletions ReactWindows/ReactNative/Views/View/ReactViewManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,65 @@ public override string Name
}
}

/// <summary>
/// Returns the view instance for <see cref="ReactViewPanel"/>.
/// </summary>
/// <param name="reactContext"></param>
/// <returns></returns>
protected override ReactViewPanel CreateViewInstanceCore(ThemedReactContext reactContext)
{
return new ReactViewPanel();
}

/// <summary>
/// The border radius of the <see cref="ReactRootView"/>.
/// </summary>
/// <param name="view">The view panel.</param>
/// <param name="borderRadius">The border radius value.</param>
[ReactProperty("borderRadius")]
public void SetBorderRadius(ReactViewPanel view, float borderRadius)
{
view.SetBorderRadius(borderRadius);
}

/// <summary>
/// Sets the elevation transformation effect of the <see cref="ReactViewPanel"/>.
/// </summary>
/// <param name="view">The view panel.</param>
/// <param name="elevation">The 3D Z-Location index of the <see cref="ReactRootView"/>.</param>
[ReactProperty("elevation")]
public void SetElevation(ReactViewPanel view, float elevation)
{
view.SetElevationEffect(elevation);
}

/// <summary>
/// Sets the border thickness of the <see cref="ReactViewPanel"/>.
/// </summary>
/// <param name="view">The view panel.</param>
/// <param name="borderWidth">The border width in pixels.</param>
[ReactProperty("borderWidth", DefaultFloat = float.NaN)]
public void SetBorderWidth(ReactViewPanel view, float borderWidth)
{
view.SetBorderThickness(borderWidth);
}

/// <summary>
/// Set the border color of the <see cref="ReactViewPanel"/>.
/// </summary>
/// <param name="view">The view panel.</param>
/// <param name="color">The color hex code.</param>
[ReactProperty("borderColor")]
public void SetBorderColor(ReactViewPanel view, string color)
{
view.SetBorderBackgroundColor(color);
}

/// <summary>
/// Sets the <see cref="ReactViewPanel"/> pointer events based on a event string key.
/// </summary>
/// <param name="view">The view panel.</param>
/// <param name="pointerEventsStr">The event to propogate down to the view.</param>
[ReactProperty("pointerEvents")]
public void SetPointerEvents(ReactViewPanel view, string pointerEventsStr)
{
Expand Down
3 changes: 2 additions & 1 deletion ReactWindows/ReactNative/Views/View/ReactViewPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ namespace ReactNative.Views.View
{
/// <summary>
/// Backing for a React View. Has support for borders, but since borders
/// aren't common, lazy initializes most of the storage needed for them.
/// aren't common, lazy initializes most of the storage needed for them. Also supports
/// 3D transformations such as elevation depth.
/// </summary>
public class ReactViewPanel : Panel, CatalystInterceptingViewGroup, ReactPointerEventsView
{
Expand Down

0 comments on commit cc26462

Please sign in to comment.