2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2015-03-23 20:35:08 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-02-20 04:10:52 +00:00
|
|
|
*
|
2018-05-11 02:06:46 +00:00
|
|
|
* @format
|
2018-05-13 06:10:49 +00:00
|
|
|
* @flow
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2018-05-11 02:06:46 +00:00
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-03-03 23:04:46 +00:00
|
|
|
const Animated = require('Animated');
|
|
|
|
const Easing = require('Easing');
|
|
|
|
const NativeMethodsMixin = require('NativeMethodsMixin');
|
|
|
|
const React = require('React');
|
|
|
|
const PropTypes = require('prop-types');
|
|
|
|
const TimerMixin = require('react-timer-mixin');
|
|
|
|
const Touchable = require('Touchable');
|
|
|
|
const TouchableWithoutFeedback = require('TouchableWithoutFeedback');
|
|
|
|
|
|
|
|
const createReactClass = require('create-react-class');
|
|
|
|
const ensurePositiveDelayProps = require('ensurePositiveDelayProps');
|
|
|
|
const flattenStyle = require('flattenStyle');
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2018-05-13 06:10:51 +00:00
|
|
|
import type {Props as TouchableWithoutFeedbackProps} from 'TouchableWithoutFeedback';
|
|
|
|
import type {ViewStyleProp} from 'StyleSheet';
|
|
|
|
|
2015-08-21 08:52:13 +00:00
|
|
|
type Event = Object;
|
|
|
|
|
2018-03-03 23:04:46 +00:00
|
|
|
const PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30};
|
2015-11-16 21:51:13 +00:00
|
|
|
|
2018-05-13 06:10:51 +00:00
|
|
|
type TVProps = $ReadOnly<{|
|
|
|
|
hasTVPreferredFocus?: ?boolean,
|
|
|
|
tvParallaxProperties?: ?Object,
|
|
|
|
|}>;
|
|
|
|
|
|
|
|
type Props = $ReadOnly<{|
|
|
|
|
...TouchableWithoutFeedbackProps,
|
|
|
|
...TVProps,
|
|
|
|
activeOpacity?: ?number,
|
|
|
|
style?: ?ViewStyleProp,
|
|
|
|
|}>;
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2015-03-09 16:28:51 +00:00
|
|
|
* A wrapper for making views respond properly to touches.
|
2015-02-20 04:10:52 +00:00
|
|
|
* On press down, the opacity of the wrapped view is decreased, dimming it.
|
2017-02-27 09:49:36 +00:00
|
|
|
*
|
|
|
|
* Opacity is controlled by wrapping the children in an Animated.View, which is
|
|
|
|
* added to the view hiearchy. Be aware that this can affect layout.
|
2015-02-20 04:10:52 +00:00
|
|
|
*
|
2015-03-09 16:28:51 +00:00
|
|
|
* Example:
|
2015-02-20 04:10:52 +00:00
|
|
|
*
|
2015-03-09 16:28:51 +00:00
|
|
|
* ```
|
|
|
|
* renderButton: function() {
|
|
|
|
* return (
|
|
|
|
* <TouchableOpacity onPress={this._onPressButton}>
|
|
|
|
* <Image
|
|
|
|
* style={styles.button}
|
2016-07-14 06:11:28 +00:00
|
|
|
* source={require('./myButton.png')}
|
2015-03-09 16:28:51 +00:00
|
|
|
* />
|
2015-03-28 22:26:15 +00:00
|
|
|
* </TouchableOpacity>
|
2015-03-09 16:28:51 +00:00
|
|
|
* );
|
|
|
|
* },
|
|
|
|
* ```
|
2017-09-13 03:25:16 +00:00
|
|
|
* ### Example
|
|
|
|
*
|
|
|
|
* ```ReactNativeWebPlayer
|
|
|
|
* import React, { Component } from 'react'
|
|
|
|
* import {
|
|
|
|
* AppRegistry,
|
|
|
|
* StyleSheet,
|
|
|
|
* TouchableOpacity,
|
|
|
|
* Text,
|
|
|
|
* View,
|
|
|
|
* } from 'react-native'
|
|
|
|
*
|
|
|
|
* class App extends Component {
|
2017-09-22 00:31:53 +00:00
|
|
|
* constructor(props) {
|
|
|
|
* super(props)
|
|
|
|
* this.state = { count: 0 }
|
|
|
|
* }
|
2017-09-13 03:25:16 +00:00
|
|
|
*
|
2017-09-22 00:31:53 +00:00
|
|
|
* onPress = () => {
|
|
|
|
* this.setState({
|
|
|
|
* count: this.state.count+1
|
|
|
|
* })
|
|
|
|
* }
|
2017-09-13 03:25:16 +00:00
|
|
|
*
|
|
|
|
* render() {
|
2017-09-22 00:31:53 +00:00
|
|
|
* return (
|
|
|
|
* <View style={styles.container}>
|
|
|
|
* <TouchableOpacity
|
2017-09-13 03:25:16 +00:00
|
|
|
* style={styles.button}
|
|
|
|
* onPress={this.onPress}
|
|
|
|
* >
|
|
|
|
* <Text> Touch Here </Text>
|
|
|
|
* </TouchableOpacity>
|
|
|
|
* <View style={[styles.countContainer]}>
|
|
|
|
* <Text style={[styles.countText]}>
|
|
|
|
* { this.state.count !== 0 ? this.state.count: null}
|
|
|
|
* </Text>
|
|
|
|
* </View>
|
|
|
|
* </View>
|
|
|
|
* )
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* const styles = StyleSheet.create({
|
|
|
|
* container: {
|
|
|
|
* flex: 1,
|
|
|
|
* justifyContent: 'center',
|
|
|
|
* paddingHorizontal: 10
|
|
|
|
* },
|
|
|
|
* button: {
|
|
|
|
* alignItems: 'center',
|
|
|
|
* backgroundColor: '#DDDDDD',
|
|
|
|
* padding: 10
|
|
|
|
* },
|
|
|
|
* countContainer: {
|
|
|
|
* alignItems: 'center',
|
|
|
|
* padding: 10
|
|
|
|
* },
|
|
|
|
* countText: {
|
|
|
|
* color: '#FF00FF'
|
|
|
|
* }
|
|
|
|
* })
|
|
|
|
*
|
|
|
|
* AppRegistry.registerComponent('App', () => App)
|
|
|
|
* ```
|
|
|
|
*
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2018-05-13 06:10:51 +00:00
|
|
|
const TouchableOpacity = ((createReactClass({
|
2017-07-07 21:24:25 +00:00
|
|
|
displayName: 'TouchableOpacity',
|
2015-07-20 23:29:40 +00:00
|
|
|
mixins: [TimerMixin, Touchable.Mixin, NativeMethodsMixin],
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
propTypes: {
|
2015-03-17 23:16:57 +00:00
|
|
|
...TouchableWithoutFeedback.propTypes,
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
|
|
|
* Determines what the opacity of the wrapped view should be when touch is
|
2016-04-29 10:44:16 +00:00
|
|
|
* active. Defaults to 0.2.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2017-04-12 23:09:48 +00:00
|
|
|
activeOpacity: PropTypes.number,
|
2017-10-18 19:16:31 +00:00
|
|
|
/**
|
Add support for Android TV devices
Summary:
<!--
Thank you for sending the PR! We appreciate you spending the time to work on these changes.
Help us understand your motivation by explaining why you decided to make this change.
You can learn more about contributing to React Native here: http://facebook.github.io/react-native/docs/contributing.html
Happy contributing!
-->
* To be on par with Apple TV support, this makes it possible to run React Native apps on Android TV devices (See also: https://react-native.canny.io/feature-requests/p/android-tv-support)
* These changes also make it possible to navigate through the app using D-PAD buttons that are present on some mobile devices
* Since these changes affect, among others, `ReactRootView.java` and `Touchable.js` code and are closely related to Apple TV implementation, it makes sense for them to be included in the core
- React native apps can be launched on Android TV devices and properly render their content
- Navigation is possible using left, right, top, bottom arrows from the remote (or D-PAD)
- Touchable components can handle D-PAD center button press events and correctly fire their `onPress` handlers
- Touchable components will receive `onPressIn` and `onPressOut` events and can react to focus/blur changes appropriately (just like on Apple TV)
- `Platform` constants allow to check if the react-native app is running on TV (`Platform.isTV`)
- `ScrollView`s behave correctly (same as native implementation) when switching to view outside bounds – that is, the container would scroll such that the newly focused element is fully visible
- Native "clicking" sounds are played when moving between focusable elements
- Play/Pause click event is send to `TVEventHandler`
- Rewind and FastForward events are send to `TVEventHandler`
- Back button behaves as a normal Android back button
- Diagonal buttons work correctly on Android TV, e.g. if there is no button directly to the right from the focused one, but there is one to the right but a bit higher/lower it will grab focus
- Dev menu can be accessed by long pressing fast forward button
A demo showing RNTester app running on Android TV device (Amazon Fire TV Stick) can be found here:
[![RNAndroidTVDemo](http://img.youtube.com/vi/EzIQErHhY20/0.jpg)](http://www.youtube.com/watch?v=EzIQErHhY20)
- `TextInput` will not work on Android TV devices. There's an issue with native `ReactEditText` implementation that prevents it from receiving focus. This makes it impossible to navigate to `TextInput`.
This will be fixed next, but will be included in a separate Pull Request
- ~Overlay permissions cannot be granted on Android TV devices running Android version >= 6.0
This is because the overlay permission can only be granted by firing an Intent to open settings page (`ACTION_MANAGE_OVERLAY_PERMISSION`). Since this page does not exist on TV devices the permission cannot be requested. This will make the app crash when trying to open dev menu (⌘+M) or displaying a redbox error.
Note: This does not affect devices running Android version < 6.0 (for example Amazon Fire TV Stick)~
This is now fixed by: https://github.com/facebook/react-native/pull/16596
* Launch the RNTester app on Android TV device.
* Ensure it launches without a crash
* Ensure basic navigation is possible
* Ensure Touchable components can receive select events
* Ensure the changes do not break current Android and iOS mobile devices functionality.
* Ensure the changes do not break current Apple TV functionality.
[RNAndroidTVDemo video](http://img.youtube.com/vi/EzIQErHhY20/0.jpg)
* Added `ReactAndroidTVViewManager` that handles TV `KeyEvent`s and dispatches events to JS - This is the core that enables basic navigation functionality on Android TV devices
* Following the above change we copy `TVEventHandler.ios.js` into `TVEventHandler.android.js` to enable JS to pick up those native navigation events and dispatch them further to subscribed views. (Note: We do not have a native `TVNavigationEventEmitter` implementation on Android, thus this file is slightly modified, e.g. it does pass `null` to `NativeEventEmitter` constructor)
* Added `uiMode` to `AndroidInfoModule`. (**Note**: This required changing `extends BaseJavaModule` to `extends ReactContextBaseJavaModule` to be able to use `getSystemService` which requires `Context` instance!
* Added `isTV` constants to both `Platform.ios.js` (keeping the deprecated `isTVOS` as well) and `Platform.android.js`
* Changed condition check on `Touchable.js` to use the newly added `isTV` flag to properly handle TV navigation events on Android as well
* Added `LEANBACK_LAUNCHER` to `RNTester` `intent-filter` so that it is possible to launch it on Android TV devices.
* See also a PR to `react-native-website` repo with updated docs for Android TV: https://github.com/facebook/react-native-website/pull/59
- [ ] Fix `TextInput` components handling by allowing them to be focused and making a proper navigation between them (and/or other components) possible. One thing to note here that the default behavior to immediately open software keyboard when focused on `TextInput` field will need to be adjusted on Android TV as well)
- [x] Fix overlay permissions issue by changing the way redbox/dev menu are displayed (see: https://github.com/facebook/react-native/pull/16596)
- [ ] Adjust placement of TV-related files (e.g. the `TVEventHandler.js` file is placed inside `AppleTV` directory which is not accurate, since it does handle Android TV events as well)
Previous discussion: https://github.com/SoftwareMansion/react-native/pull/1
<!--
Help reviewers and the release process by writing your own release notes
**INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.**
CATEGORY
[----------] TYPE
[ CLI ] [-------------] LOCATION
[ DOCS ] [ BREAKING ] [-------------]
[ GENERAl ] [ BUGFIX ] [-{Component}-]
[ INTERNAL ] [ ENHANCEMENT ] [ {File} ]
[ IOS ] [ FEATURE ] [ {Directory} ] |-----------|
[ ANDROID ] [ MINOR ] [ {Framework} ] - | {Message} |
[----------] [-------------] [-------------] |-----------|
[CATEGORY] [TYPE] [LOCATION] - MESSAGE
EXAMPLES:
[IOS] [BREAKING] [FlatList] - Change a thing that breaks other things
[ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput
[CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with
[DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word
[GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position
[INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see
-->
[ANDROID] [FEATURE] [TV] - Added support for Android TV devices
Closes https://github.com/facebook/react-native/pull/16500
Differential Revision: D6536847
Pulled By: hramos
fbshipit-source-id: 17bbb11e8583b97f195ced5fd9762f8902fb8a3d
2018-03-06 18:41:27 +00:00
|
|
|
* TV preferred focus (see documentation for the View component).
|
2017-10-18 19:16:31 +00:00
|
|
|
*/
|
|
|
|
hasTVPreferredFocus: PropTypes.bool,
|
2016-12-19 14:26:07 +00:00
|
|
|
/**
|
|
|
|
* Apple TV parallax effects
|
|
|
|
*/
|
2017-04-12 23:09:48 +00:00
|
|
|
tvParallaxProperties: PropTypes.object,
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
2015-04-01 04:25:51 +00:00
|
|
|
activeOpacity: 0.2,
|
2015-02-20 04:10:52 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
2015-07-20 23:29:40 +00:00
|
|
|
return {
|
|
|
|
...this.touchableGetInitialState(),
|
2017-03-02 05:28:53 +00:00
|
|
|
anim: new Animated.Value(this._getChildStyleOpacityWithDefault()),
|
2015-07-20 23:29:40 +00:00
|
|
|
};
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount: function() {
|
[Touchable] Add custom delay props to Touchable components
Summary:
@public
This PR adds quite a bit of functionality to the Touchable components, allowing the ms delays of each of the handlers (`onPressIn, onPressOut, onPress, onLongPress`) to be configured.
It adds the following props to `TouchableWithoutFeedback, TouchableOpacity, and TouchableHighlight`:
```javascript
/**
* Delay in ms, from the release of the touch, before onPress is called.
*/
delayOnPress: React.PropTypes.number,
/**
* Delay in ms, from the start of the touch, before onPressIn is called.
*/
delayOnPressIn: React.PropTypes.number,
/**
* Delay in ms, from the release of the touch, before onPressOut is called.
*/
delayOnPressOut: React.PropTypes.number,
/**
* Delay in ms, from onPressIn, before onLongPress is called.
*/
delayOnLongPress: React.PropTypes.number,
```
`TouchableHighlight` also gets an additional set of props:
```javascript
/**
* Delay in ms, from the start of the touch, before the highlight is shown.
*/
delayHighlightShow: React.PropTypes.number,
/**
* Del
...
```
Closes https://github.com/facebook/react-native/pull/1255
Github Author: jmstout <git@jmstout.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-03 19:56:32 +00:00
|
|
|
ensurePositiveDelayProps(this.props);
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
|
2018-02-08 18:26:45 +00:00
|
|
|
UNSAFE_componentWillReceiveProps: function(nextProps) {
|
[Touchable] Add custom delay props to Touchable components
Summary:
@public
This PR adds quite a bit of functionality to the Touchable components, allowing the ms delays of each of the handlers (`onPressIn, onPressOut, onPress, onLongPress`) to be configured.
It adds the following props to `TouchableWithoutFeedback, TouchableOpacity, and TouchableHighlight`:
```javascript
/**
* Delay in ms, from the release of the touch, before onPress is called.
*/
delayOnPress: React.PropTypes.number,
/**
* Delay in ms, from the start of the touch, before onPressIn is called.
*/
delayOnPressIn: React.PropTypes.number,
/**
* Delay in ms, from the release of the touch, before onPressOut is called.
*/
delayOnPressOut: React.PropTypes.number,
/**
* Delay in ms, from onPressIn, before onLongPress is called.
*/
delayOnLongPress: React.PropTypes.number,
```
`TouchableHighlight` also gets an additional set of props:
```javascript
/**
* Delay in ms, from the start of the touch, before the highlight is shown.
*/
delayHighlightShow: React.PropTypes.number,
/**
* Del
...
```
Closes https://github.com/facebook/react-native/pull/1255
Github Author: jmstout <git@jmstout.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-03 19:56:32 +00:00
|
|
|
ensurePositiveDelayProps(nextProps);
|
|
|
|
},
|
|
|
|
|
2018-03-05 23:46:32 +00:00
|
|
|
componentDidUpdate: function(prevProps, prevState) {
|
|
|
|
if (this.props.disabled !== prevProps.disabled) {
|
|
|
|
this._opacityInactive(250);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-04-09 18:12:46 +00:00
|
|
|
/**
|
|
|
|
* Animate the touchable to a new opacity.
|
|
|
|
*/
|
2016-12-13 19:21:48 +00:00
|
|
|
setOpacityTo: function(value: number, duration: number) {
|
2018-05-11 02:06:46 +00:00
|
|
|
Animated.timing(this.state.anim, {
|
|
|
|
toValue: value,
|
|
|
|
duration: duration,
|
|
|
|
easing: Easing.inOut(Easing.quad),
|
|
|
|
useNativeDriver: true,
|
|
|
|
}).start();
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* `Touchable.Mixin` self callbacks. The mixin will invoke these if they are
|
|
|
|
* defined on your component.
|
|
|
|
*/
|
2015-08-21 08:52:13 +00:00
|
|
|
touchableHandleActivePressIn: function(e: Event) {
|
2016-11-14 17:29:18 +00:00
|
|
|
if (e.dispatchConfig.registrationName === 'onResponderGrant') {
|
|
|
|
this._opacityActive(0);
|
|
|
|
} else {
|
|
|
|
this._opacityActive(150);
|
|
|
|
}
|
2015-08-21 08:52:13 +00:00
|
|
|
this.props.onPressIn && this.props.onPressIn(e);
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
|
2015-08-21 08:52:13 +00:00
|
|
|
touchableHandleActivePressOut: function(e: Event) {
|
2016-12-13 19:21:48 +00:00
|
|
|
this._opacityInactive(250);
|
2015-08-21 08:52:13 +00:00
|
|
|
this.props.onPressOut && this.props.onPressOut(e);
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
|
2015-08-21 08:52:13 +00:00
|
|
|
touchableHandlePress: function(e: Event) {
|
|
|
|
this.props.onPress && this.props.onPress(e);
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
|
2015-08-21 08:52:13 +00:00
|
|
|
touchableHandleLongPress: function(e: Event) {
|
|
|
|
this.props.onLongPress && this.props.onLongPress(e);
|
2015-02-26 18:03:22 +00:00
|
|
|
},
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
touchableGetPressRectOffset: function() {
|
2015-11-16 21:51:13 +00:00
|
|
|
return this.props.pressRetentionOffset || PRESS_RETENTION_OFFSET;
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
|
2016-02-17 00:50:35 +00:00
|
|
|
touchableGetHitSlop: function() {
|
|
|
|
return this.props.hitSlop;
|
|
|
|
},
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
touchableGetHighlightDelayMS: function() {
|
[Touchable] Add custom delay props to Touchable components
Summary:
@public
This PR adds quite a bit of functionality to the Touchable components, allowing the ms delays of each of the handlers (`onPressIn, onPressOut, onPress, onLongPress`) to be configured.
It adds the following props to `TouchableWithoutFeedback, TouchableOpacity, and TouchableHighlight`:
```javascript
/**
* Delay in ms, from the release of the touch, before onPress is called.
*/
delayOnPress: React.PropTypes.number,
/**
* Delay in ms, from the start of the touch, before onPressIn is called.
*/
delayOnPressIn: React.PropTypes.number,
/**
* Delay in ms, from the release of the touch, before onPressOut is called.
*/
delayOnPressOut: React.PropTypes.number,
/**
* Delay in ms, from onPressIn, before onLongPress is called.
*/
delayOnLongPress: React.PropTypes.number,
```
`TouchableHighlight` also gets an additional set of props:
```javascript
/**
* Delay in ms, from the start of the touch, before the highlight is shown.
*/
delayHighlightShow: React.PropTypes.number,
/**
* Del
...
```
Closes https://github.com/facebook/react-native/pull/1255
Github Author: jmstout <git@jmstout.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-03 19:56:32 +00:00
|
|
|
return this.props.delayPressIn || 0;
|
|
|
|
},
|
|
|
|
|
|
|
|
touchableGetLongPressDelayMS: function() {
|
2018-05-11 02:06:46 +00:00
|
|
|
return this.props.delayLongPress === 0
|
|
|
|
? 0
|
|
|
|
: this.props.delayLongPress || 500;
|
[Touchable] Add custom delay props to Touchable components
Summary:
@public
This PR adds quite a bit of functionality to the Touchable components, allowing the ms delays of each of the handlers (`onPressIn, onPressOut, onPress, onLongPress`) to be configured.
It adds the following props to `TouchableWithoutFeedback, TouchableOpacity, and TouchableHighlight`:
```javascript
/**
* Delay in ms, from the release of the touch, before onPress is called.
*/
delayOnPress: React.PropTypes.number,
/**
* Delay in ms, from the start of the touch, before onPressIn is called.
*/
delayOnPressIn: React.PropTypes.number,
/**
* Delay in ms, from the release of the touch, before onPressOut is called.
*/
delayOnPressOut: React.PropTypes.number,
/**
* Delay in ms, from onPressIn, before onLongPress is called.
*/
delayOnLongPress: React.PropTypes.number,
```
`TouchableHighlight` also gets an additional set of props:
```javascript
/**
* Delay in ms, from the start of the touch, before the highlight is shown.
*/
delayHighlightShow: React.PropTypes.number,
/**
* Del
...
```
Closes https://github.com/facebook/react-native/pull/1255
Github Author: jmstout <git@jmstout.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-03 19:56:32 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
touchableGetPressOutDelayMS: function() {
|
|
|
|
return this.props.delayPressOut;
|
|
|
|
},
|
|
|
|
|
2016-11-14 17:29:18 +00:00
|
|
|
_opacityActive: function(duration: number) {
|
|
|
|
this.setOpacityTo(this.props.activeOpacity, duration);
|
[Touchable] Add custom delay props to Touchable components
Summary:
@public
This PR adds quite a bit of functionality to the Touchable components, allowing the ms delays of each of the handlers (`onPressIn, onPressOut, onPress, onLongPress`) to be configured.
It adds the following props to `TouchableWithoutFeedback, TouchableOpacity, and TouchableHighlight`:
```javascript
/**
* Delay in ms, from the release of the touch, before onPress is called.
*/
delayOnPress: React.PropTypes.number,
/**
* Delay in ms, from the start of the touch, before onPressIn is called.
*/
delayOnPressIn: React.PropTypes.number,
/**
* Delay in ms, from the release of the touch, before onPressOut is called.
*/
delayOnPressOut: React.PropTypes.number,
/**
* Delay in ms, from onPressIn, before onLongPress is called.
*/
delayOnLongPress: React.PropTypes.number,
```
`TouchableHighlight` also gets an additional set of props:
```javascript
/**
* Delay in ms, from the start of the touch, before the highlight is shown.
*/
delayHighlightShow: React.PropTypes.number,
/**
* Del
...
```
Closes https://github.com/facebook/react-native/pull/1255
Github Author: jmstout <git@jmstout.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-03 19:56:32 +00:00
|
|
|
},
|
|
|
|
|
2016-12-13 19:21:48 +00:00
|
|
|
_opacityInactive: function(duration: number) {
|
2018-05-11 02:06:46 +00:00
|
|
|
this.setOpacityTo(this._getChildStyleOpacityWithDefault(), duration);
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
|
2017-03-02 05:28:53 +00:00
|
|
|
_getChildStyleOpacityWithDefault: function() {
|
2018-05-11 02:06:46 +00:00
|
|
|
const childStyle = flattenStyle(this.props.style) || {};
|
|
|
|
return childStyle.opacity == undefined ? 1 : childStyle.opacity;
|
|
|
|
},
|
2016-12-19 14:26:07 +00:00
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
render: function() {
|
2015-07-20 23:29:40 +00:00
|
|
|
return (
|
|
|
|
<Animated.View
|
2016-06-21 15:24:07 +00:00
|
|
|
accessible={this.props.accessible !== false}
|
2016-02-04 13:12:36 +00:00
|
|
|
accessibilityLabel={this.props.accessibilityLabel}
|
2018-07-26 00:33:58 +00:00
|
|
|
accessibilityHint={this.props.accessibilityHint}
|
2018-07-26 06:37:16 +00:00
|
|
|
accessibilityRole={this.props.accessibilityRole}
|
|
|
|
accessibilityStates={this.props.accessibilityStates}
|
2015-07-20 23:29:40 +00:00
|
|
|
style={[this.props.style, {opacity: this.state.anim}]}
|
2017-04-07 18:47:35 +00:00
|
|
|
nativeID={this.props.nativeID}
|
2015-07-20 23:29:40 +00:00
|
|
|
testID={this.props.testID}
|
2015-09-01 17:31:20 +00:00
|
|
|
onLayout={this.props.onLayout}
|
2016-12-19 14:26:07 +00:00
|
|
|
isTVSelectable={true}
|
2017-10-18 19:16:31 +00:00
|
|
|
hasTVPreferredFocus={this.props.hasTVPreferredFocus}
|
2016-12-19 14:26:07 +00:00
|
|
|
tvParallaxProperties={this.props.tvParallaxProperties}
|
2016-02-17 00:50:35 +00:00
|
|
|
hitSlop={this.props.hitSlop}
|
2015-07-20 23:29:40 +00:00
|
|
|
onStartShouldSetResponder={this.touchableHandleStartShouldSetResponder}
|
2018-05-11 02:06:46 +00:00
|
|
|
onResponderTerminationRequest={
|
|
|
|
this.touchableHandleResponderTerminationRequest
|
|
|
|
}
|
2015-07-20 23:29:40 +00:00
|
|
|
onResponderGrant={this.touchableHandleResponderGrant}
|
|
|
|
onResponderMove={this.touchableHandleResponderMove}
|
|
|
|
onResponderRelease={this.touchableHandleResponderRelease}
|
|
|
|
onResponderTerminate={this.touchableHandleResponderTerminate}>
|
|
|
|
{this.props.children}
|
2018-05-11 02:06:46 +00:00
|
|
|
{Touchable.renderDebugView({
|
|
|
|
color: 'cyan',
|
|
|
|
hitSlop: this.props.hitSlop,
|
|
|
|
})}
|
2015-07-20 23:29:40 +00:00
|
|
|
</Animated.View>
|
|
|
|
);
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
2018-05-13 06:10:51 +00:00
|
|
|
}): any): React.ComponentType<Props>);
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
module.exports = TouchableOpacity;
|