forked from Ivasoft/mattermost-mobile
* Upgrade to RN 0.62.0 * Update packager module paths * Fix Android PasteableInput * Fix regression on Android share extension credentials needed * Update android/app/src/main/java/com/mattermost/rnbeta/RNPasteableEditTextOnPasteListener.java * Reject commit if TSC check fails and Fix small eslint issues automatically * Use super.getExportedCustomBubblingEventTypeConstants in RNPasteableTextInputManager * Update to rn 0.62.2 Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>
65 lines
1.6 KiB
JavaScript
65 lines
1.6 KiB
JavaScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import {NativeEventEmitter, NativeModules, Platform, TextInput} from 'react-native';
|
|
|
|
const {OnPasteEventManager} = NativeModules;
|
|
const OnPasteEventEmitter = new NativeEventEmitter(OnPasteEventManager);
|
|
|
|
export class PasteableTextInput extends React.PureComponent {
|
|
static propTypes = {
|
|
...TextInput.PropTypes,
|
|
onPaste: PropTypes.func,
|
|
forwardRef: PropTypes.any,
|
|
}
|
|
|
|
componentDidMount() {
|
|
this.subscription = OnPasteEventEmitter.addListener('onPaste', this.onPaste);
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
if (this.subscription) {
|
|
this.subscription.remove();
|
|
}
|
|
}
|
|
|
|
onPaste = (event) => {
|
|
const {onPaste} = this.props;
|
|
let data = null;
|
|
let error = null;
|
|
|
|
if (Platform.OS === 'android') {
|
|
const {nativeEvent} = event;
|
|
data = nativeEvent.data;
|
|
error = nativeEvent.error;
|
|
} else {
|
|
data = event;
|
|
}
|
|
|
|
return onPaste?.(error, data);
|
|
}
|
|
|
|
render() {
|
|
const {forwardRef, ...props} = this.props;
|
|
|
|
return (
|
|
<TextInput
|
|
{...props}
|
|
onPaste={this.onPaste}
|
|
ref={forwardRef}
|
|
/>
|
|
);
|
|
}
|
|
}
|
|
|
|
const WrappedPasteableTextInput = (props, ref) => (
|
|
<PasteableTextInput
|
|
{...props}
|
|
forwardRef={ref}
|
|
/>
|
|
);
|
|
|
|
export default React.forwardRef(WrappedPasteableTextInput);
|