Authored by chenl

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

@@ -218,7 +218,8 @@ export default class Brand extends Component { @@ -218,7 +218,8 @@ export default class Brand extends Component {
218 onTextChange={this.props.onTextChange} 218 onTextChange={this.props.onTextChange}
219 onClickCancel={this.props.onClickCancel} 219 onClickCancel={this.props.onClickCancel}
220 onPressClearHistory={this.props.onPressClearHistory} 220 onPressClearHistory={this.props.onPressClearHistory}
221 - onPressBrandSearchItem={this.props.onPressBrandSearchItem} /> : null} 221 + onPressBrandSearchItem={this.props.onPressBrandSearchItem}
  222 + onPressSearchHistoryItem={this.props.onPressSearchHistoryItem} /> : null}
222 </View> 223 </View>
223 ); 224 );
224 } 225 }
@@ -53,9 +53,7 @@ export default class BrandSearch extends Component { @@ -53,9 +53,7 @@ export default class BrandSearch extends Component {
53 history={history} 53 history={history}
54 hot={hot} 54 hot={hot}
55 onPressClearHistory={this.props.onPressClearHistory} 55 onPressClearHistory={this.props.onPressClearHistory}
56 - onPressKeyword={(keyword) => {  
57 - this.props.onTextChange(keyword);  
58 - }} 56 + onPressKeyword={this.props.onPressSearchHistoryItem}
59 />} 57 />}
60 58
61 </View> 59 </View>
@@ -36,7 +36,7 @@ export default class KeywordCell extends React.Component { @@ -36,7 +36,7 @@ export default class KeywordCell extends React.Component {
36 /> 36 />
37 <View style={styles.textContainer}> 37 <View style={styles.textContainer}>
38 {list.toJS().map((item, i) => { 38 {list.toJS().map((item, i) => {
39 - return <KeywordText key={i} keyword={item.keyword} onPressKeyword={onPressKeyword}/>; 39 + return <KeywordText key={i} keyword={item.keyword} androiddata={item.androiddata} onPressKeyword={onPressKeyword}/>;
40 })} 40 })}
41 </View> 41 </View>
42 42
@@ -23,14 +23,14 @@ export default class KeywordText extends React.Component { @@ -23,14 +23,14 @@ export default class KeywordText extends React.Component {
23 } 23 }
24 24
25 render() { 25 render() {
26 - let {keyword, onPressKeyword} = this.props; 26 + let {keyword, androiddata, onPressKeyword} = this.props;
27 let textColor = this.state.helight ? {color: 'rgb(66, 66, 66)'} : {color: 'rgb(191, 191, 191)'}; 27 let textColor = this.state.helight ? {color: 'rgb(66, 66, 66)'} : {color: 'rgb(191, 191, 191)'};
28 return ( 28 return (
29 <TouchableHighlight 29 <TouchableHighlight
30 style={styles.container} 30 style={styles.container}
31 underlayColor={'rgb(255, 255, 255)'} 31 underlayColor={'rgb(255, 255, 255)'}
32 onPress={() => { 32 onPress={() => {
33 - onPressKeyword && onPressKeyword(keyword); 33 + onPressKeyword && onPressKeyword(keyword, androiddata);
34 }} 34 }}
35 onPressIn={() => { 35 onPressIn={() => {
36 this.setState({ 36 this.setState({
@@ -59,6 +59,7 @@ class BrandContainer extends Component { @@ -59,6 +59,7 @@ class BrandContainer extends Component {
59 this._setBrandData = this._setBrandData.bind(this); 59 this._setBrandData = this._setBrandData.bind(this);
60 this._setInitialListSize = this._setInitialListSize.bind(this); 60 this._setInitialListSize = this._setInitialListSize.bind(this);
61 this._onPressBrandItem = this._onPressBrandItem.bind(this); 61 this._onPressBrandItem = this._onPressBrandItem.bind(this);
  62 + this._onPressSearchHistoryItem = this._onPressSearchHistoryItem.bind(this);
62 63
63 64
64 this.subscription = NativeAppEventEmitter.addListener( 65 this.subscription = NativeAppEventEmitter.addListener(
@@ -167,11 +168,20 @@ class BrandContainer extends Component { @@ -167,11 +168,20 @@ class BrandContainer extends Component {
167 168
168 _onPressBrandSearchItem(data) { 169 _onPressBrandSearchItem(data) {
169 this._onPressBrandItem(data); 170 this._onPressBrandItem(data);
170 - let brandName = data.brand_name ? data.brand_name : '';  
171 - this.props.actions.insertSearchHistory(brandName); 171 + this.props.actions.insertSearchHistory(data);
172 this._onClickCancelSearch(); 172 this._onClickCancelSearch();
173 } 173 }
174 174
  175 + _onPressSearchHistoryItem(keyword, androiddata){
  176 + //兼容IOS只需要搜索关键字,IOS设置搜索框内容为keyword即可,android需要点击直接跳转至相关页面
  177 + if (Platform.OS === 'ios') {
  178 + this._onSearchTextChange(keyword);
  179 + }
  180 + else{
  181 + this._onPressBrandItem(androiddata);
  182 + }
  183 + }
  184 +
175 render() { 185 render() {
176 let { 186 let {
177 showSearch, 187 showSearch,
@@ -218,6 +228,7 @@ class BrandContainer extends Component { @@ -218,6 +228,7 @@ class BrandContainer extends Component {
218 setBrandData={this._setBrandData} 228 setBrandData={this._setBrandData}
219 setInitialListSize={this._setInitialListSize} 229 setInitialListSize={this._setInitialListSize}
220 onPressBrandItem={this._onPressBrandItem} 230 onPressBrandItem={this._onPressBrandItem}
  231 + onPressSearchHistoryItem={this._onPressSearchHistoryItem}
221 /> 232 />
222 </View> 233 </View>
223 ); 234 );
1 'use strict'; 1 'use strict';
2 2
3 import ReactNative from 'react-native'; 3 import ReactNative from 'react-native';
  4 +import {Platform} from 'react-native';
4 import BrandService from '../../services/BrandService'; 5 import BrandService from '../../services/BrandService';
5 import {Record, List, Map} from 'immutable'; 6 import {Record, List, Map} from 'immutable';
6 import Pinyin from '../../../common/utils/pinyin'; 7 import Pinyin from '../../../common/utils/pinyin';
@@ -414,18 +415,34 @@ export function searchHistory() { @@ -414,18 +415,34 @@ export function searchHistory() {
414 }; 415 };
415 } 416 }
416 417
417 -export function insertSearchHistory(keyword) { 418 +export function insertSearchHistory(data) {
418 return (dispatch, getState) => { 419 return (dispatch, getState) => {
419 - ReactNative.NativeModules.YH_ClassifyHelper.insertSearchHistory(keyword)  
420 - .then(data => {  
421 - dispatch({  
422 - type: INSERT_BRAND_SEARCH_HISTORY,  
423 - payload: parseSearchHistory(data)  
424 - });  
425 - })  
426 - .catch(error => { 420 + //兼容IOS只需要搜索关键字,android需要整个data数据
  421 + if (Platform.OS === 'ios') {
  422 + let brandName = data.brand_name ? data.brand_name : '';
  423 + ReactNative.NativeModules.YH_ClassifyHelper.insertSearchHistory(brandName)
  424 + .then(data => {
  425 + dispatch({
  426 + type: INSERT_BRAND_SEARCH_HISTORY,
  427 + payload: parseSearchHistory(data)
  428 + });
  429 + })
  430 + .catch(error => {
427 431
428 - }); 432 + });
  433 + }
  434 + else{
  435 + ReactNative.NativeModules.YH_ClassifyHelper.insertSearchHistory(data)
  436 + .then(data => {
  437 + dispatch({
  438 + type: INSERT_BRAND_SEARCH_HISTORY,
  439 + payload: parseSearchHistory(data)
  440 + });
  441 + })
  442 + .catch(error => {
  443 +
  444 + });
  445 + }
429 }; 446 };
430 } 447 }
431 448
@@ -447,7 +464,13 @@ export function clearSearchHistory() { @@ -447,7 +464,13 @@ export function clearSearchHistory() {
447 function parseSearchHistory(data) { 464 function parseSearchHistory(data) {
448 let list = []; 465 let list = [];
449 data.map((item, i) => { 466 data.map((item, i) => {
450 - list.push({keyword: item}); 467 + //兼容IOS只需要搜索关键字,android需要整个data数据
  468 + if (Platform.OS === 'ios') {
  469 + list.push({keyword: item});
  470 + }
  471 + else{
  472 + list.push({keyword: item.brand_name, androiddata: item});
  473 + }
451 }); 474 });
452 475
453 return list; 476 return list;