-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Expand file tree
/
Copy pathInputAccessoryView.js
More file actions
83 lines (76 loc) · 2.66 KB
/
Copy pathInputAccessoryView.js
File metadata and controls
83 lines (76 loc) · 2.66 KB
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
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/
import SafeAreaView from '../../../src/private/components/safeareaview/SafeAreaView';
import StyleSheet, {
type ColorValue,
type ViewStyleProp,
} from '../../StyleSheet/StyleSheet';
import Platform from '../../Utilities/Platform';
import useWindowDimensions from '../../Utilities/useWindowDimensions';
import RCTInputAccessoryViewNativeComponent from './RCTInputAccessoryViewNativeComponent';
import * as React from 'react';
/**
* InputAccessoryView is deprecated and will be removed in a future release.
* @deprecated
* @build-types emit-as-interface Expo compatibility
*/
export type InputAccessoryViewProps = Readonly<{
readonly children: React.Node,
/**
* An ID used to associate this `InputAccessoryView` to specified `TextInput`(s).
*/
nativeID?: ?string,
style?: ?ViewStyleProp,
backgroundColor?: ?ColorValue,
}>;
/**
* A component which enables customization of the keyboard input accessory view on iOS. The input accessory view is displayed above the keyboard whenever a `TextInput` has focus. This component can be used to create custom toolbars.
*
* To use this component, wrap your custom toolbar with `InputAccessoryView` and set a `nativeID`. Then, pass that `nativeID` as the `inputAccessoryViewID` of whatever `TextInput` you desire.
*
* This component can also be used to create sticky text inputs (text inputs which are anchored to the top of the keyboard). To do this, wrap a `TextInput` with `InputAccessoryView` and don't set a `nativeID`.
*
* InputAccessoryView is deprecated and will be removed in a future release.
*
* @platform ios
* @deprecated
*/
const InputAccessoryView: React.ComponentType<InputAccessoryViewProps> = (
props: InputAccessoryViewProps,
) => {
const {width} = useWindowDimensions();
if (Platform.OS === 'ios') {
if (React.Children.count(props.children) === 0) {
return null;
}
return (
<RCTInputAccessoryViewNativeComponent
style={[props.style, styles.container]}
nativeID={props.nativeID}
backgroundColor={props.backgroundColor}>
<SafeAreaView style={[styles.safeAreaView, {width}]}>
{props.children}
</SafeAreaView>
</RCTInputAccessoryViewNativeComponent>
);
} else {
console.warn('<InputAccessoryView> is only supported on iOS.');
return null;
}
};
const styles = StyleSheet.create({
container: {
position: 'absolute',
},
safeAreaView: {
flex: 1,
},
});
export default InputAccessoryView;