2015-09-14 14:35:58 +00:00
|
|
|
/**
|
2016-11-23 05:01:36 +00:00
|
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
2015-09-14 14:35:58 +00:00
|
|
|
* The examples provided by Facebook are for non-commercial testing and
|
|
|
|
* evaluation purposes only.
|
|
|
|
*
|
|
|
|
* Facebook reserves all rights not expressly granted.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* @providesModule SearchBar
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-04-09 03:36:40 +00:00
|
|
|
var React = require('react');
|
|
|
|
var ReactNative = require('react-native');
|
2016-11-23 05:01:36 +00:00
|
|
|
|
|
|
|
var nativeImageSource = require('nativeImageSource');
|
2015-09-14 14:35:58 +00:00
|
|
|
var {
|
|
|
|
Image,
|
|
|
|
Platform,
|
2016-06-14 05:15:47 +00:00
|
|
|
ActivityIndicator,
|
2015-09-14 14:35:58 +00:00
|
|
|
TextInput,
|
|
|
|
StyleSheet,
|
|
|
|
TouchableNativeFeedback,
|
|
|
|
View,
|
2016-04-09 03:36:40 +00:00
|
|
|
} = ReactNative;
|
2015-09-14 14:35:58 +00:00
|
|
|
|
|
|
|
var IS_RIPPLE_EFFECT_SUPPORTED = Platform.Version >= 21;
|
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
class SearchBar extends React.Component {
|
|
|
|
render() {
|
2015-09-14 14:35:58 +00:00
|
|
|
var background = IS_RIPPLE_EFFECT_SUPPORTED ?
|
|
|
|
TouchableNativeFeedback.SelectableBackgroundBorderless() :
|
|
|
|
TouchableNativeFeedback.SelectableBackground();
|
|
|
|
return (
|
|
|
|
<View style={styles.searchBar}>
|
|
|
|
<TouchableNativeFeedback
|
|
|
|
background={background}
|
|
|
|
onPress={() => this.refs.input && this.refs.input.focus()}>
|
|
|
|
<View>
|
|
|
|
<Image
|
2016-11-23 05:01:36 +00:00
|
|
|
source={nativeImageSource({
|
|
|
|
android: 'android_search_white',
|
|
|
|
width: 96,
|
|
|
|
height: 96
|
|
|
|
})}
|
2015-09-14 14:35:58 +00:00
|
|
|
style={styles.icon}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
</TouchableNativeFeedback>
|
|
|
|
<TextInput
|
|
|
|
ref="input"
|
|
|
|
autoCapitalize="none"
|
|
|
|
autoCorrect={false}
|
|
|
|
autoFocus={true}
|
|
|
|
onChange={this.props.onSearchChange}
|
|
|
|
placeholder="Search a movie..."
|
|
|
|
placeholderTextColor="rgba(255, 255, 255, 0.5)"
|
|
|
|
onFocus={this.props.onFocus}
|
|
|
|
style={styles.searchBarInput}
|
|
|
|
/>
|
2016-06-14 05:15:47 +00:00
|
|
|
<ActivityIndicator
|
|
|
|
animating={this.props.isLoading}
|
|
|
|
color="white"
|
|
|
|
size="large"
|
|
|
|
style={styles.spinner}
|
|
|
|
/>
|
2015-09-14 14:35:58 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-09-14 14:35:58 +00:00
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
|
|
|
searchBar: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
backgroundColor: '#a9a9a9',
|
|
|
|
height: 56,
|
|
|
|
},
|
|
|
|
searchBarInput: {
|
|
|
|
flex: 1,
|
|
|
|
fontSize: 20,
|
|
|
|
fontWeight: 'bold',
|
|
|
|
color: 'white',
|
|
|
|
height: 50,
|
|
|
|
padding: 0,
|
|
|
|
backgroundColor: 'transparent'
|
|
|
|
},
|
|
|
|
spinner: {
|
|
|
|
width: 30,
|
|
|
|
height: 30,
|
2016-06-14 05:15:47 +00:00
|
|
|
marginRight: 16,
|
2015-09-14 14:35:58 +00:00
|
|
|
},
|
|
|
|
icon: {
|
|
|
|
width: 24,
|
|
|
|
height: 24,
|
|
|
|
marginHorizontal: 8,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = SearchBar;
|