Authored by chenl

增加了兼容Android点击搜索关键字直接进行搜索跳转。

... ... @@ -218,7 +218,8 @@ export default class Brand extends Component {
onTextChange={this.props.onTextChange}
onClickCancel={this.props.onClickCancel}
onPressClearHistory={this.props.onPressClearHistory}
onPressBrandSearchItem={this.props.onPressBrandSearchItem} /> : null}
onPressBrandSearchItem={this.props.onPressBrandSearchItem}
onPressSearchHistoryItem={this.props.onPressSearchHistoryItem} /> : null}
</View>
);
}
... ...
... ... @@ -53,9 +53,7 @@ export default class BrandSearch extends Component {
history={history}
hot={hot}
onPressClearHistory={this.props.onPressClearHistory}
onPressKeyword={(keyword) => {
this.props.onTextChange(keyword);
}}
onPressKeyword={this.props.onPressSearchHistoryItem}
/>}
</View>
... ...
... ... @@ -36,7 +36,7 @@ export default class KeywordCell extends React.Component {
/>
<View style={styles.textContainer}>
{list.toJS().map((item, i) => {
return <KeywordText key={i} keyword={item.keyword} onPressKeyword={onPressKeyword}/>;
return <KeywordText key={i} keyword={item.keyword} androiddata={item.androiddata} onPressKeyword={onPressKeyword}/>;
})}
</View>
... ...
... ... @@ -23,14 +23,14 @@ export default class KeywordText extends React.Component {
}
render() {
let {keyword, onPressKeyword} = this.props;
let {keyword, androiddata, onPressKeyword} = this.props;
let textColor = this.state.helight ? {color: 'rgb(66, 66, 66)'} : {color: 'rgb(191, 191, 191)'};
return (
<TouchableHighlight
style={styles.container}
underlayColor={'rgb(255, 255, 255)'}
onPress={() => {
onPressKeyword && onPressKeyword(keyword);
onPressKeyword && onPressKeyword(keyword, androiddata);
}}
onPressIn={() => {
this.setState({
... ...
... ... @@ -59,6 +59,7 @@ class BrandContainer extends Component {
this._setBrandData = this._setBrandData.bind(this);
this._setInitialListSize = this._setInitialListSize.bind(this);
this._onPressBrandItem = this._onPressBrandItem.bind(this);
this._onPressSearchHistoryItem = this._onPressSearchHistoryItem.bind(this);
this.subscription = NativeAppEventEmitter.addListener(
... ... @@ -167,11 +168,20 @@ class BrandContainer extends Component {
_onPressBrandSearchItem(data) {
this._onPressBrandItem(data);
let brandName = data.brand_name ? data.brand_name : '';
this.props.actions.insertSearchHistory(brandName);
this.props.actions.insertSearchHistory(data);
this._onClickCancelSearch();
}
_onPressSearchHistoryItem(keyword, androiddata){
//兼容IOS只需要搜索关键字,IOS设置搜索框内容为keyword即可,android需要点击直接跳转至相关页面
if (Platform.OS === 'ios') {
this._onSearchTextChange(keyword);
}
else{
this._onPressBrandItem(androiddata);
}
}
render() {
let {
showSearch,
... ... @@ -218,6 +228,7 @@ class BrandContainer extends Component {
setBrandData={this._setBrandData}
setInitialListSize={this._setInitialListSize}
onPressBrandItem={this._onPressBrandItem}
onPressSearchHistoryItem={this._onPressSearchHistoryItem}
/>
</View>
);
... ...
'use strict';
import ReactNative from 'react-native';
import {Platform} from 'react-native';
import BrandService from '../../services/BrandService';
import {Record, List, Map} from 'immutable';
import Pinyin from '../../../common/utils/pinyin';
... ... @@ -414,18 +415,34 @@ export function searchHistory() {
};
}
export function insertSearchHistory(keyword) {
export function insertSearchHistory(data) {
return (dispatch, getState) => {
ReactNative.NativeModules.YH_ClassifyHelper.insertSearchHistory(keyword)
.then(data => {
dispatch({
type: INSERT_BRAND_SEARCH_HISTORY,
payload: parseSearchHistory(data)
});
})
.catch(error => {
//兼容IOS只需要搜索关键字,android需要整个data数据
if (Platform.OS === 'ios') {
let brandName = data.brand_name ? data.brand_name : '';
ReactNative.NativeModules.YH_ClassifyHelper.insertSearchHistory(brandName)
.then(data => {
dispatch({
type: INSERT_BRAND_SEARCH_HISTORY,
payload: parseSearchHistory(data)
});
})
.catch(error => {
});
});
}
else{
ReactNative.NativeModules.YH_ClassifyHelper.insertSearchHistory(data)
.then(data => {
dispatch({
type: INSERT_BRAND_SEARCH_HISTORY,
payload: parseSearchHistory(data)
});
})
.catch(error => {
});
}
};
}
... ... @@ -447,7 +464,13 @@ export function clearSearchHistory() {
function parseSearchHistory(data) {
let list = [];
data.map((item, i) => {
list.push({keyword: item});
//兼容IOS只需要搜索关键字,android需要整个data数据
if (Platform.OS === 'ios') {
list.push({keyword: item});
}
else{
list.push({keyword: item.brand_name, androiddata: item});
}
});
return list;
... ...