Skip to content

Commit

Permalink
Fixes #32 - Adds UIManagerModule constants
Browse files Browse the repository at this point in the history
Some remaining TODOs include integrating the constants from the view managers, and further investigation on how to include other features available in Android.
  • Loading branch information
rozele committed Dec 26, 2015
1 parent a5bf6f3 commit cd54b61
Show file tree
Hide file tree
Showing 10 changed files with 357 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using ReactNative.Bridge;
using ReactNative.Modules.Core;
using ReactNative.UIManager;
using ReactNative.UIManager.Events;
using System;
using System.Collections.Generic;
using System.Threading;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using Newtonsoft.Json.Linq;
using ReactNative.Modules.Core;
using ReactNative.UIManager.Events;

namespace ReactNative.Tests.UIManager.Events
{
Expand Down
1 change: 1 addition & 0 deletions ReactWindows/ReactNative/CoreModulesPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using ReactNative.Modules.Core;
using ReactNative.Tracing;
using ReactNative.UIManager;
using ReactNative.UIManager.Events;
using System;
using System.Collections.Generic;
using Windows.UI.Xaml;
Expand Down
4 changes: 4 additions & 0 deletions ReactWindows/ReactNative/ReactNative.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@
<Compile Include="Tracing\TraceDisposable.cs" />
<Compile Include="Tracing\Tracer.cs" />
<Compile Include="UIManager\AppRegistry.cs" />
<Compile Include="UIManager\Events\TouchEventType.cs" />
<Compile Include="UIManager\Events\TouchEventTypeExtensions.cs" />
<Compile Include="UIManager\PointerEvents.cs" />
<Compile Include="UIManager\SizeMonitoringFrameLayout.cs" />
<Compile Include="UIManager\NativeViewHierarchyManager.cs" />
<Compile Include="UIManager\ReactProp.cs" />
Expand All @@ -211,6 +214,7 @@
<Compile Include="UIManager\UIImplementation.cs" />
<Compile Include="UIManager\UIImplementationProvider.cs" />
<Compile Include="UIManager\UIManagerModule.cs" />
<Compile Include="UIManager\UIManagerModule.Constants.cs" />
<Compile Include="UIManager\UIViewOperationQueue.cs" />
<Compile Include="UIManager\ViewManager.cs" />
<Compile Include="UIManager\ViewManagerRegistry.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Newtonsoft.Json.Linq;
using ReactNative.Bridge;

namespace ReactNative.Modules.Core
namespace ReactNative.UIManager.Events
{
/// <summary>
/// JavaScript event emitter.
Expand Down
29 changes: 29 additions & 0 deletions ReactWindows/ReactNative/UIManager/Events/TouchEventType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace ReactNative.UIManager.Events
{
/// <summary>
/// Touch event types that the JavaScript module <see cref="RCTEventEmitter"/>
/// understands.
/// </summary>
public enum TouchEventType
{
/// <summary>
/// Touch start event type.
/// </summary>
Start,

/// <summary>
/// Touch end event type.
/// </summary>
End,

/// <summary>
/// Touch move event type.
/// </summary>
Move,

/// <summary>
/// Touch cancel event type.
/// </summary>
Cancel,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;

namespace ReactNative.UIManager.Events
{
static class TouchEventTypeExtensions
{
public static string GetJavaScriptEventName(this TouchEventType eventType)
{
switch (eventType)
{
case TouchEventType.Start:
return "topTouchStart";
case TouchEventType.End:
return "topTouchEnd";
case TouchEventType.Move:
return "topTouchMove";
case TouchEventType.Cancel:
return "topTouchCancel";
default:
throw new NotSupportedException("Unsupported touch event type.");
}
}
}
}
30 changes: 30 additions & 0 deletions ReactWindows/ReactNative/UIManager/PointerEvents.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace ReactNative.UIManager
{
/// <summary>
/// Possible values for pointer events that a view and its descendants should
/// receive. See https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events
/// for more information.
/// </summary>
public enum PointerEvents
{
/// <summary>
/// Neither the container nor its children receive events.
/// </summary>
None,

/// <summary>
/// Container does not get events but all its children do.
/// </summary>
BoxNone,

/// <summary>
/// Container gets events but none of its children do.
/// </summary>
BoxOnly,

/// <summary>
/// Container and all of its children receive touch events.
/// </summary>
Auto,
}
}
260 changes: 260 additions & 0 deletions ReactWindows/ReactNative/UIManager/UIManagerModule.Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
using ReactNative.UIManager.Events;
using System.Collections.Generic;

namespace ReactNative.UIManager
{
using Windows.UI.Xaml;
using Map = Dictionary<string, object>;

public partial class UIManagerModule
{
private const string CUSTOM_BUBBLING_EVENT_TYPES_KEY = "customBubblingEventTypes";
private const string CUSTOM_DIRECT_EVENT_TYPES_KEY = "customDirectEventTypes";

public const string ACTION_DISMISSED = "dismissed";
public const string ACTION_ITEM_SELECTED = "itemSelected";

public static IDictionary<string, object> CreateConstants(IReadOnlyList<ViewManager<FrameworkElement, ReactShadowNode>> viewManagers)
{
var constants = GetConstants();
var bubblingEventTypesConstants = GetBubblingEventTypeConstants();
var directEventTypesConstants = GetDirectEventTypeConstants();

foreach (var viewManager in viewManagers)
{
// TODO: add view manager exports
}

constants.Add(CUSTOM_BUBBLING_EVENT_TYPES_KEY, bubblingEventTypesConstants);
constants.Add(CUSTOM_DIRECT_EVENT_TYPES_KEY, directEventTypesConstants);

return constants;
}

public static IDictionary<string, object> GetBubblingEventTypeConstants()
{
return new Map
{
{
"topChange",
new Map
{
{
"phasedRegistrationNames",
new Map
{
{ "bubbled", "onChange" },
{ "captured", "onChangeCapture" },
}
}
}
},
{
"topSelect",
new Map
{
{
"phasedRegistrationNames",
new Map
{
{ "bubbled", "onSelect" },
{ "captured", "onSelectCapture" },
}
}
}
},
{
TouchEventType.Start.GetJavaScriptEventName(),
new Map
{
{
"phasedRegistrationName",
new Map
{
{ "bubbled", "onTouchStart" },
{ "captured", "onTouchStartCapture" },
}
}
}
},
{
TouchEventType.Move.GetJavaScriptEventName(),
new Map
{
{
"phasedRegistrationName",
new Map
{
{ "bubbled", "onTouchMove" },
{ "captured", "onTouchMoveCapture" },
}
}
}
},
{
TouchEventType.Start.GetJavaScriptEventName(),
new Map
{
{
"phasedRegistrationName",
new Map
{
{ "bubbled", "onTouchEnd" },
{ "captured", "onTouchEndCapture" },
}
}
}
},
};
}

public static IDictionary<string, object> GetDirectEventTypeConstants()
{
return new Map
{
{
"topSelectionChange",
new Map
{
{ "registrationName", "onSelectionChange" },
}
},
{
"topLoadingStart",
new Map
{
{ "registrationName", "onLoadingStart" },
}
},
{
"topLoadingFinish",
new Map
{
{ "registrationName", "onLoadingFinish" },
}
},
{
"topLoadingError",
new Map
{
{ "registrationName", "onLoadingError" },
}
},
{
"topLayout",
new Map
{
{ "registrationName", "onLayout" },
}
},
};
}

public static IDictionary<string, object> GetConstants()
{
return new Map
{
{
"UIView",
new Map
{
{
"ContentMode",
new Map
{
/* TODO: declare content mode properties */
}
},
}
},
{
"UIText",
new Map
{
{
"AutocapitalizationType",
new Map
{
/* TODO: declare capitalization types */
}
},
}
},
{
"Dimensions",
new Map
{
{
"window",
new Dictionary<string, object>
{
{ "width", 100 },
{ "height", 100 },
{ "scale", 1 },
/* TODO: verify values? */
/* TODO: density and DPI needed? */
}
},
}
},
{
"StyleConstants",
new Map
{
{
"PointerEventsValues",
new Map
{
{ "none", PointerEvents.None.ToString() },
{ "boxNone", PointerEvents.BoxNone.ToString() },
{ "boxOnly", PointerEvents.BoxOnly.ToString() },
{ "unspecified", PointerEvents.Auto.ToString() },
}
},
}
},
{
"PopupMenu",
new Map
{
{ ACTION_DISMISSED, ACTION_DISMISSED },
{ ACTION_ITEM_SELECTED, ACTION_ITEM_SELECTED },
}
},
{
"AccessibilityEventTypes",
new Map
{
/* TODO: declare accessibility event types */
}
},
};
}

private static void RecursiveMerge(IDictionary<string, object> sink, IDictionary<string, object> source)
{
foreach (var pair in source)
{
var existing = default(object);
if (sink.TryGetValue(pair.Key, out existing))
{
var sourceAsMap = pair.Value as IDictionary<string, object>;
var sinkAsMap = existing as IDictionary<string, object>;
if (sourceAsMap != null && sinkAsMap != null)
{
RecursiveMerge(sinkAsMap, sourceAsMap);
}
else
{
// TODO: replace with exception?
sink.Add(pair.Key, pair.Value);
}
}
else
{
sink.Add(pair.Key, pair.Value);
}
}
}
}
}
Loading

0 comments on commit cd54b61

Please sign in to comment.