Determines the inputs that the component can provide. The component can always support text input and extra inputs can be supported by adding actions.
Called immediately before mounting occurs, and before Component#render
.
Avoid introducing any side-effects or subscriptions in this method.
This method will not stop working in React 17.
Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.
Called when the component may be receiving new props. React may call this even if props have not changed, so be sure to compare new and existing props if you only want to handle changes.
Calling Component#setState
generally does not trigger this method.
This method will not stop working in React 17.
Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.
Called immediately before rendering when new props or state is received. Not called for the initial render.
Note: You cannot call Component#setState
here.
This method will not stop working in React 17.
Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.
Catches exceptions generated in descendant components. Unhandled exceptions will cause the entire component tree to unmount.
Called immediately before mounting occurs, and before Component#render
.
Avoid introducing any side-effects or subscriptions in this method.
Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.
Called when the component may be receiving new props. React may call this even if props have not changed, so be sure to compare new and existing props if you only want to handle changes.
Calling Component#setState
generally does not trigger this method.
Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.
Called immediately before a component is destroyed. Perform any necessary cleanup in this method, such as
cancelled network requests, or cleaning up any DOM elements created in componentDidMount
.
Called immediately before rendering when new props or state is received. Not called for the initial render.
Note: You cannot call Component#setState
here.
Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.
Runs before React applies the result of render
to the document, and
returns an object to be given to componentDidUpdate. Useful for saving
things such as scroll position before render
causes changes to it.
Note: the presence of getSnapshotBeforeUpdate prevents any of the deprecated lifecycle events from running.
Called to determine whether the change in props and state should trigger a re-render.
Component
always returns true.
PureComponent
implements a shallow comparison on props and state and returns true if any
props or states have changed.
If false is returned, Component#render
, componentWillUpdate
and componentDidUpdate
will not be called.
The chat input, by default, provides a simple text input component. However, an array of
IAction
interfaces can be provided that can extend the input to provide many types of inputs flows.The default operation of the input component is to provide a way for the user to enter text and send it. The text is provided to the
onInput
callback function for processing. The send button can be customised by overriding theSendButtonComponent
property, or setting the staticInput.SendButtonComponent
variable to override it application wide.Most chat input require more than just text input. The chat input provides an extensible actions interface to allow completely custom input methods to be implemented. Multiple actions can be provided to the input element. All actions must implement a promise that returns some user input. The resolved user input is routed through the same
onInput
callback function that the text is routed through. This makes it easy to construct control flows for various user inputs. Optionally, the action can provide a React Native component that is rendered instead of the default text input. This allows complete control of the user experience whilst providing input to the chat application.import { IInputMutable, InputText, isIInputText as isIInputText } from '@ef-carbon/input'; import { IInputActionImmutable, Input, InputAction, KeyboardSpacer } from '@ef-carbon/react-native-chat';
export interface IProps { }
export class MyComponent extends React.PureComponent {
render(): React.ReactNode { *
return ;
}
private readonly handleInput = async (data: IInputMutable): Promise => {
const text = isIInputText(data) ? data.text : 'Unknown...';
return new Promise(resolve => Alert.alert(
'Input',
text,
[
{ text: 'OK', onPress: resolve },
],
{ cancelable: false },
));
}
}
`