-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #32 - Adds UIManagerModule constants
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
Showing
10 changed files
with
357 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
ReactWindows/ReactNative.Tests/UIManager/Events/RCTEventEmitterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
ReactWindows/ReactNative/UIManager/Events/TouchEventType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
ReactWindows/ReactNative/UIManager/Events/TouchEventTypeExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
260
ReactWindows/ReactNative/UIManager/UIManagerModule.Constants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.