import { Component, ReactNode, createElement, createRef } from "react"; import { TextStyle, ViewStyle, TextInput, View } from "react-native"; import { Style, mergeNativeStyles } from "@mendix/pluggable-widgets-tools"; import { AutosearchProps } from "../typings/AutosearchProps"; export interface AutosearchStyle extends Style { container: ViewStyle; label: TextStyle; input: ViewStyle; } interface State { textboxValue?: string; } const defaultStyle: AutosearchStyle = { container: { }, label: { color: "#003C85" }, input: { }, text: { color: "#003C85", fontSize: 15, paddingTop: 10, paddingLeft: 10, paddingBottom: 10 } }; export class Autosearch extends Component, State> { private readonly styles = mergeNativeStyles(defaultStyle, this.props.style); private readonly onChangeHandler = this.onChange.bind(this); private readonly onTouchStart = this.onTouch.bind(this); private readonly onEndHandler = this.onEnd.bind(this); inputRef = createRef(); constructor(props: AutosearchProps){ super(props) this.state = { textboxValue: '', } } componentDidUpdate(prevProps: AutosearchProps) { if (prevProps.autoFocus !== this.props.autoFocus) { if (this.props.autoFocus.value) { setTimeout(() => { this.inputRef.current?.focus(); this.props.autoFocus.setValue(false); return; }, 500) } } if (prevProps.searchvalue !== this.props.searchvalue) { if (this.props.searchvalue === undefined || this.props.searchvalue.displayValue === '') { this.setState({textboxValue: ''}); this.inputRef.current?.clear; } } } render(): ReactNode { return ( ) } private onChange(text: string) { this.setState({textboxValue: text}); this.props.searchvalue.setValue(text); } private onTouch() { this.props.onEnter?.execute(); } private onEnd() { this.props.onChange?.execute(); } }