From e0fc3f3c1abefd04014b899a86bd841720c314a2 Mon Sep 17 00:00:00 2001 From: bang Date: Wed, 21 Aug 2019 10:15:43 +0800 Subject: [PATCH] fix: type definition of search-bar --- components/search-bar/PropsType.tsx | 6 ++++-- components/search-bar/index.tsx | 11 +++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/components/search-bar/PropsType.tsx b/components/search-bar/PropsType.tsx index 6f3349e3e..bb6a067e3 100644 --- a/components/search-bar/PropsType.tsx +++ b/components/search-bar/PropsType.tsx @@ -1,3 +1,5 @@ +import { NativeSyntheticEvent, TextInputFocusEventData } from "react-native"; + function noop() {} export interface SearchBarPropsType { @@ -6,8 +8,8 @@ export interface SearchBarPropsType { placeholder?: string; onSubmit?: (value: string) => void; onChange?: (value: string) => void; - onFocus?: () => void; - onBlur?: () => void; + onFocus?: (e: NativeSyntheticEvent) => void; + onBlur?: (e: NativeSyntheticEvent) => void; onCancel?: (value: string) => void; showCancelButton?: boolean; cancelText?: string; diff --git a/components/search-bar/index.tsx b/components/search-bar/index.tsx index d4025201f..9a2d109af 100644 --- a/components/search-bar/index.tsx +++ b/components/search-bar/index.tsx @@ -1,7 +1,6 @@ - import PropTypes from 'prop-types'; import React from 'react'; -import { StyleProp, Text, TextInput, TextStyle, View } from 'react-native'; +import { NativeSyntheticEvent, StyleProp, Text, TextInput, TextInputFocusEventData, TextStyle, View } from 'react-native'; import Icon from '../icon'; import { WithTheme, WithThemeStyles } from '../style'; import { getComponentLocale } from '../_util/getLocale'; @@ -75,21 +74,21 @@ export default class SearchBar extends React.Component< } }; - onFocus = () => { + onFocus = (e: NativeSyntheticEvent) => { this.setState({ focus: true, }); if (this.props.onFocus) { - this.props.onFocus(); + this.props.onFocus(e); } }; - onBlur = () => { + onBlur = (e: NativeSyntheticEvent) => { this.setState({ focus: false, }); if (this.props.onBlur) { - this.props.onBlur(); + this.props.onBlur(e); } }; render() {