Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Klemenski committed Jul 7, 2021
1 parent 017845e commit 6856878
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const {
View,
StyleSheet,
Slider,
Switch
Switch,
} = require('react-native');
const {useState} = React;

Expand Down Expand Up @@ -169,12 +169,13 @@ function PropagationSample() {
}
return (
<>
<View focusable
style={styles.row}
// keyDownEvents={[
// {code: 'KeyW', handledEventPhase: 3},
// {code: 'KeyE', handledEventPhase: 1},
// ]}
<View
focusable
style={styles.row}
keyDownEvents={[
{code: 'KeyW', handledEventPhase: 3},
{code: 'KeyE', handledEventPhase: 1},
]}
onKeyDown={event => logEvent('outer keyDown ' + event.nativeEvent.code)}
onKeyDownCapture={event =>
logEvent('outer keyDownCapture ' + event.nativeEvent.code)
Expand All @@ -183,8 +184,12 @@ function PropagationSample() {
<TextInput
placeholder="Click inside the box to observe events being fired."
style={[styles.singleLineWithHeightTextInput]}
onKeyDown={event => logEvent('textinput keyDown ' + event.nativeEvent.code)}
onKeyUp={event => logEvent('textinput keyUp ' + event.nativeEvent.code)}
onKeyDown={event =>
logEvent('textinput keyDown ' + event.nativeEvent.code)
}
onKeyUp={event =>
logEvent('textinput keyUp ' + event.nativeEvent.code)
}
keyDownEvents={[
{code: 'KeyW', handledEventPhase: 3},
{code: 'KeyE', handledEventPhase: 1},
Expand Down Expand Up @@ -534,7 +539,7 @@ exports.examples = ([
{
title: 'Stop propagation sample',
render: function(): React.Node {
return <PropagationSample/>;
return <PropagationSample />;
},
},
// Windows]
Expand Down
7 changes: 5 additions & 2 deletions vnext/src/Libraries/Components/TextInput/TextInput.windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -1142,11 +1142,14 @@ function InternalTextInput(props: Props): React.Node {
// TextInput handles onBlur and onFocus events
// so omitting onBlur and onFocus pressability handlers here.
const {onBlur, onFocus, ...eventHandlers} = usePressability(config) || {};
const eventPhase = Object.freeze({Capturing:1, Bubbling:3});
const eventPhase = Object.freeze({Capturing: 1, Bubbling: 3});
const _keyDown = (event: KeyEvent) => {
if (props.keyDownEvents && event.isPropagationStopped() !== true) {
for (const el of props.keyDownEvents) {
if (event.nativeEvent.code == el.code && el.handledEventPhase == eventPhase.Bubbling) {
if (
event.nativeEvent.code == el.code &&
el.handledEventPhase == eventPhase.Bubbling
) {
event.stopPropagation();
}
}
Expand Down

0 comments on commit 6856878

Please sign in to comment.