Skip to content

Conversation

@licanhua
Copy link
Contributor

@licanhua licanhua commented Jun 17, 2019

Fix #2469.

Add supportKeyboard, and this function can add to any Controls. The whole implementation is simplified three small tasks:

  1. RootView dispatches topKeyDown/topKeyUp when PreviewKeyDown/ PreviewKeyUp happened on RootView. Target would be the OriginalSource id.
  2. If keyDownEvents or keyUpEvents is set, mark that control’s handled to true based on the condition.
  3. In GetExportedCustomBubblingEventTypeConstants, add keyDown and keyUp.

Example code for customer to use it:

const handledNativeKeyboardEvents: IHandledKeyboardEvent[] = [
  { key: 'a', handledEventPhase:  HandledEventPhase.Capturing },
  { key: 'b' },
  { key: 'c', handledEventPhase:  HandledEventPhase.Bubbling },
  { key: 'Tab', handledEventPhase: HandledEventPhase.Capturing }
];

const ViewWindows = supportKeyboard(View)
        <ViewWindows
          style={styles.keyComponentRoot}
          onKeyDownCapture={this._onKeyDownCapture}
          onKeyUpCapture={this._onKeyUpCapture}
          onKeyUp={this._onKeyUp}
          onKeyDown={this._onKeyDown}
          keyDownEvents={handledNativeKeyboardEvents} 
          keyUpEvents={handledNativeKeyboardEvents}
        >

Note:

  1. user never receive key='a' events, and it's always be 'A'.
  2. key 'a' and 'A' are the same meaning in HandledKeyboardEvent
  3. exact match is done for HandledKeyboardEvent. that means 'a', 'a'+shift, 'a'+alt' and 'a'+shift+alt are not the same.
Microsoft Reviewers: Open in CodeFlow

@licanhua licanhua requested a review from a team as a code owner June 17, 2019 19:35
@ghost ghost added the vnext label Jun 17, 2019
Copy link
Member

@ahimberg ahimberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕐

@ghost ghost added the Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) label Jun 19, 2019
@ghost ghost removed the Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) label Jun 19, 2019
@ghost ghost removed the Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) label Jun 20, 2019
Copy link
Contributor

@kmelmon kmelmon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@licanhua licanhua requested review from ahimberg and randy-flynn June 22, 2019 01:34
@licanhua licanhua added the AutoMerge Causes a PR to be automatically merged once all requirements are passed (label drives bot activity) label Jun 22, 2019
@ghost
Copy link

ghost commented Jun 22, 2019

Hello @licanhua!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

Copy link
Contributor

@randy-flynn randy-flynn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@ghost ghost merged commit b8d9791 into microsoft:master Jun 24, 2019
@licanhua licanhua deleted the keyboard branch June 24, 2019 20:48
@harinikmsft harinikmsft added this to the vNext Milestone 2 milestone Aug 2, 2019
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AutoMerge Causes a PR to be automatically merged once all requirements are passed (label drives bot activity)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Keyboard events

6 participants