// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. /* eslint-disable no-underscore-dangle */ import React from 'react'; import {TextInput, Text, TouchableWithoutFeedback} from 'react-native'; import UIManager from 'UIManager'; import invariant from 'invariant'; import requireNativeComponent from 'requireNativeComponent'; const AndroidTextInput = requireNativeComponent('PasteableTextInputAndroid'); // This class is copied from React Native's TextInput // All credit goes to React Native team // Source: https://github.com/facebook/react-native/blob/master/Libraries/Components/TextInput/TextInput.js#L1056 class CustomTextInput extends TextInput { // Override React Native's TextInput render for Android _renderAndroid = () => { const props = Object.assign({}, this.props); props.style = [this.props.style]; props.autoCapitalize = UIManager.getViewManagerConfig( 'AndroidTextInput', ).Constants.AutoCapitalizationType[props.autoCapitalize || 'sentences']; let children = this.props.children; let childCount = 0; React.Children.forEach(children, () => ++childCount); invariant( !(this.props.value && childCount), 'Cannot specify both value and children.', ); if (childCount > 1) { children = {children}; } if (props.selection && props.selection.end == null) { props.selection = { start: props.selection.start, end: props.selection.start, }; } const textContainer = ( ); return ( {textContainer} ); }; _onPaste = (event) => { const {nativeEvent} = event; const {onPaste} = this.props; return onPaste?.(nativeEvent.error, nativeEvent.data); } } export default CustomTextInput;