-
Notifications
You must be signed in to change notification settings - Fork 494
/
RootView.tsx
105 lines (92 loc) · 2.83 KB
/
RootView.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* RootView.tsx
*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT license.
*
* The top-most view that's used for proper layering or modals and popups.
*/
import * as React from 'react';
import * as RN from 'react-native';
import * as RNW from 'react-native-windows';
import {
BaseRootView,
BaseRootViewProps,
RootView as RootViewBase,
RootViewPropsWithMainViewType,
RootViewState,
RootViewUsingProps as RootViewUsingPropsBase
} from '../native-desktop/RootView';
import { AccessibilityAnnouncer } from './AccessibilityAnnouncer';
//
// We use a custom RNW provided component to capture key input before being dispatched to native controls.
// If support not present, we fallback to the base class implementation.
const _isRootInputViewSupported = !!RNW.RootInputViewWindows;
const _styles = RN.StyleSheet.create({
appWrapperStyle : {
flex: 1
}
});
type Handler = (e: RN.NativeSyntheticEvent<any>) => void;
function _renderTopView(
content: JSX.Element, onKeyDown: Handler, onKeyDownCapture: Handler, onKeyUp: Handler, onTouchStartCapture: Handler): JSX.Element {
return (
<RNW.RootInputViewWindows
onTouchStartCapture={ onTouchStartCapture }
onAccelKeyDown={ (e: RN.NativeSyntheticEvent<any>) => {onKeyDownCapture(e); onKeyDown(e); } }
onAccelKeyUp={ onKeyUp }
style={ _styles.appWrapperStyle }
>
{ content }
</RNW.RootInputViewWindows>
);
}
class RootViewUsingStore extends RootViewBase {
renderTopView(content: JSX.Element): JSX.Element {
if (_isRootInputViewSupported) {
return _renderTopView(
content,
this._onKeyDown,
this._onKeyDownCapture,
this._onKeyUp,
this._onTouchStartCapture
);
} else {
return super.renderTopView(content);
}
}
protected _renderAnnouncerView(): JSX.Element {
return (
<AccessibilityAnnouncer />
);
}
}
class RootViewUsingProps extends RootViewUsingPropsBase {
renderTopView(content: JSX.Element): JSX.Element {
if (_isRootInputViewSupported) {
return _renderTopView (
content,
this._onKeyDown,
this._onKeyDownCapture,
this._onKeyUp,
this._onTouchStartCapture
);
} else {
return super.renderTopView(content);
}
}
protected _renderAnnouncerView(): JSX.Element {
return (
<AccessibilityAnnouncer />
);
}
}
export {
BaseRootViewProps,
RootViewPropsWithMainViewType,
RootViewState,
BaseRootView,
RootViewUsingStore as RootView,
RootViewUsingProps
};
export default RootViewUsingStore;