Skip to content

Commit

Permalink
feat(ControlWindows): Adds control component for tab stops
Browse files Browse the repository at this point in the history
ControlWindows is a UserControl with a single child Canvas. It has props to enable tab stop, tab index, keyboard navigation mode, and keyUp/Down events.

Fixes microsoft#886
  • Loading branch information
rozele committed Oct 5, 2017
1 parent 7bc4479 commit 20ae297
Show file tree
Hide file tree
Showing 13 changed files with 787 additions and 69 deletions.
12 changes: 12 additions & 0 deletions Libraries/Components/ControlWindows/ControlWindows.android.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* All rights reserved.
*
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule ControlWindows
*/
'use strict';

module.exports = require('UnimplementedView');
12 changes: 12 additions & 0 deletions Libraries/Components/ControlWindows/ControlWindows.ios.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* All rights reserved.
*
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule ControlWindows
*/
'use strict';

module.exports = require('UnimplementedView');
101 changes: 101 additions & 0 deletions Libraries/Components/ControlWindows/ControlWindows.windows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* All rights reserved.
*
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule ControlWindows
*/
'use strict';

var PropTypes = require('prop-types');
var React = require('React');
var ViewPropTypes = require('ViewPropTypes');
var requireNativeComponent = require('requireNativeComponent');

class ControlWindows extends React.Component {

static propTypes = {
...ViewPropTypes,

/**
* Controls whether the view is a tab stop. Useful for buttons and other
* controls that can be focused.
*
* @platform windows
*/
isTabStop: PropTypes.bool,

/**
* Sets the tab index for the view.
*
* @platform windows
*/
tabIndex: PropTypes.number,

/**
* Sets the keyboard navigation mode for the view.
*
* @platform windows
*/
tabNavigation: PropTypes.oneOf([
'local',
'cycle',
'once'
]),

/**
* Called when the view receives focus.
*
* @platform windows
*/
onFocus: PropTypes.func,

/**
* Called when the view focus is lost.
*
* @platform windows
*/
onBlur: PropTypes.func,

/**
* Set of keys that should be handled on key down by this component.
*
* @platform windows
*/
handledKeyDownKeys: PropTypes.arrayOf(PropTypes.number),

/**
* Set of keys that should be handled on key up by this component.
*
* @platform windows
*/
handledKeyUpKeys: PropTypes.arrayOf(PropTypes.number),

/**
* Called when key down while component has focus.
*
* @platform windows
*/
onKeyDown: PropTypes.func,

/**
* Called when key up while component has focus.
*
* @platform windows
*/
onKeyUp: PropTypes.func,
};

render() {
return <WindowsControl {...this.props}/>;
}
}

var WindowsControl = requireNativeComponent(
'WindowsControl',
ControlWindows
);

module.exports = ControlWindows;
1 change: 1 addition & 0 deletions Libraries/react-native-windows/react-native-windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

var ReactWindows = {
// Components
get ControlWindows() { return require('ControlWindows'); },
get FlipViewWindows() { return require('FlipViewWindows'); },
get PasswordBoxWindows() { return require('PasswordBoxWindows'); },
get ProgressBarWindows() {return require('ProgressBarWindows');},
Expand Down
5 changes: 3 additions & 2 deletions ReactWindows/ReactNative.Net46/Shell/MainReactPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
using ReactNative.Modules.Clipboard;
using ReactNative.Modules.Core;
using ReactNative.Modules.Dialog;
using ReactNative.Modules.Image;
using ReactNative.Modules.I18N;
using ReactNative.Modules.Image;
using ReactNative.Modules.NetInfo;
using ReactNative.Modules.Network;
using ReactNative.Modules.Storage;
using ReactNative.Modules.WebSocket;
using ReactNative.UIManager;
using ReactNative.Views.Control;
using ReactNative.Views.Image;
using ReactNative.Views.Picker;
using ReactNative.Views.Progress;
Expand Down Expand Up @@ -69,13 +70,13 @@ public IReadOnlyList<IViewManager> CreateViewManagers(
{
return new List<IViewManager>
{
new ReactControlManager(),
//new ReactFlipViewManager(),
new ReactImageManager(),
new ReactProgressBarViewManager(),
//new ReactProgressRingViewManager(),
new ReactPickerManager(),
new ReactRunManager(),
////new RecyclerViewBackedScrollViewManager(),
new ReactScrollViewManager(),
new ReactSliderManager(),
//new ReactSplitViewManager(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace ReactNative.Views.TextInput
{
using Control = System.Windows.Controls.Control;

/// <summary>
/// Represents an adorner that adds placeholder text to a <see cref="T:System.Windows.Controls.TextBox"/>,
/// <see cref="T:System.Windows.Controls.RichTextBox"/> or <see cref="T:System.Windows.Controls.PasswordBox"/>.
Expand Down
5 changes: 4 additions & 1 deletion ReactWindows/ReactNative.Shared/ReactNative.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@
<Compile Include="$(MSBuildThisFileDirectory)UIManager\Annotations\ReactPropBaseAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UIManager\Annotations\ReactPropGroupAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UIManager\AppRegistry.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UIManager\BorderedCanvas.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UIManager\BorderExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UIManager\ColorHelpers.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UIManager\IUIBlock.cs" />
Expand Down Expand Up @@ -212,6 +211,9 @@
<Compile Include="$(MSBuildThisFileDirectory)UIManager\ViewParentManagerExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UIManager\ViewProps.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UIManager\YogaNodePool.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Views\Control\KeyHelpers.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Views\Control\ReactControl.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Views\Control\ReactControlManager.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Views\Image\ReactImageLoadEvent.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Views\Scroll\ScrollEventType.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Views\Scroll\ScrollEventTypeExtensions.cs" />
Expand All @@ -238,6 +240,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Views\TextInput\ReactTextInputSubmitEditingEvent.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Views\Text\TextDecorationLine.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Views\ViewManagersPropertyCache.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Views\View\ReactCanvas.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Views\View\ReactViewManager.cs" />
</ItemGroup>
</Project>
35 changes: 35 additions & 0 deletions ReactWindows/ReactNative.Shared/Views/Control/KeyHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
#if WINDOWS_UWP
using Windows.System;
#else
using System.Windows.Input;
#endif

namespace ReactNative.Views.Control
{
#if WINDOWS_UWP
using Key = VirtualKey;
#endif

static class KeyHelpers
{
public static int GetKeyCode(this Key key)
{
return (int)key;
}

public static IReadOnlyDictionary<string, int> GetKeyConstants()
{
return Enum.GetValues(typeof(Key))
.OfType<Key>()
.Distinct() // Distinct() required*
.ToDictionary(
key => key.ToString(),
key => GetKeyCode(key));
// *The following keys are duplicated in Enum.GetValues(Type):
// `Hangul`, `Kanji`
}
}
}
59 changes: 59 additions & 0 deletions ReactWindows/ReactNative.Shared/Views/Control/ReactControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#if WINDOWS_UWP
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
#else
using System.Windows;
using System.Windows.Controls;
#endif

namespace ReactNative.Views.Control
{
/// <summary>
/// A native control with a single Canvas child.
/// </summary>
public class ReactControl : UserControl
{
private readonly Canvas _canvas;

/// <summary>
/// Instantiates the <see cref="ReactControl"/>.
/// </summary>
public ReactControl()
{
Content = _canvas = new Canvas
{
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Stretch,
};
}

/// <summary>
/// The view children.
/// </summary>
public UIElementCollection Children
{
get
{
return _canvas.Children;
}
}

/// <summary>
/// Keys that should be handled during <see cref="UIElement.KeyDownEvent"/>.
/// </summary>
public int[] HandledKeyDownKeys
{
get;
set;
}

/// <summary>
/// Keys that should be handled during <see cref="UIElement.KeyUpEvent"/>.
/// </summary>
public int[] HandledKeyUpKeys
{
get;
set;
}
}
}
Loading

0 comments on commit 20ae297

Please sign in to comment.