2015-01-30 01:10:49 +00:00
/ * *
2015-03-26 18:24:15 +00:00
* The examples provided by Facebook are for non - commercial testing and
* evaluation purposes only .
2015-03-23 22:07:33 +00:00
*
2015-03-26 18:24:15 +00:00
* 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 .
2015-03-23 22:07:33 +00:00
*
* @ flow
2015-01-30 01:10:49 +00:00
* /
'use strict' ;
2016-04-09 03:36:40 +00:00
var React = require ( 'react' ) ;
var ReactNative = require ( 'react-native' ) ;
2015-01-30 01:10:49 +00:00
var {
StyleSheet ,
Text ,
View ,
2016-04-09 03:36:40 +00:00
} = ReactNative ;
2015-01-30 01:10:49 +00:00
var ExampleBox = React . createClass ( {
getInitialState : function ( ) {
return {
log : [ ] ,
} ;
} ,
handleLog : function ( msg ) {
this . state . log = this . state . log . concat ( [ msg ] ) ;
} ,
flushReactChanges : function ( ) {
this . forceUpdate ( ) ;
} ,
/ * *
* Capture phase of bubbling to append separator before any of the bubbling
* happens .
* /
handleTouchCapture : function ( ) {
this . state . log = this . state . log . concat ( [ '---' ] ) ;
} ,
render : function ( ) {
return (
< View >
< View
onTouchEndCapture = { this . handleTouchCapture }
onTouchStart = { this . flushReactChanges } >
< this . props . Component onLog = { this . handleLog } / >
< / V i e w >
< View
style = { styles . logBox } >
< DemoText style = { styles . logText } >
{ this . state . log . join ( '\n' ) }
< / D e m o T e x t >
< / V i e w >
< / V i e w >
) ;
}
} ) ;
var NoneExample = React . createClass ( {
render : function ( ) {
return (
< View
onTouchStart = { ( ) => this . props . onLog ( 'A unspecified touched' ) }
style = { styles . box } >
< DemoText style = { styles . text } >
A : unspecified
< / D e m o T e x t >
< View
2015-03-05 05:06:49 +00:00
pointerEvents = "none"
2015-01-30 01:10:49 +00:00
onTouchStart = { ( ) => this . props . onLog ( 'B none touched' ) }
style = { [ styles . box , styles . boxPassedThrough ] } >
< DemoText style = { [ styles . text , styles . textPassedThrough ] } >
B : none
< / D e m o T e x t >
< View
onTouchStart = { ( ) => this . props . onLog ( 'C unspecified touched' ) }
style = { [ styles . box , styles . boxPassedThrough ] } >
< DemoText style = { [ styles . text , styles . textPassedThrough ] } >
C : unspecified
< / D e m o T e x t >
< / V i e w >
< / V i e w >
< / V i e w >
) ;
}
} ) ;
/ * *
* Special demo text that makes itself untouchable so that it doesn ' t destroy
* the experiment and confuse the output .
* /
var DemoText = React . createClass ( {
render : function ( ) {
return (
2015-03-05 05:06:49 +00:00
< View pointerEvents = "none" >
2015-01-30 01:10:49 +00:00
< Text
style = { this . props . style } >
{ this . props . children }
< / T e x t >
< / V i e w >
) ;
}
} ) ;
var BoxNoneExample = React . createClass ( {
render : function ( ) {
return (
< View
onTouchStart = { ( ) => this . props . onLog ( 'A unspecified touched' ) }
style = { styles . box } >
< DemoText style = { styles . text } >
A : unspecified
< / D e m o T e x t >
< View
2015-03-05 05:06:49 +00:00
pointerEvents = "box-none"
onTouchStart = { ( ) => this . props . onLog ( 'B box-none touched' ) }
2015-01-30 01:10:49 +00:00
style = { [ styles . box , styles . boxPassedThrough ] } >
< DemoText style = { [ styles . text , styles . textPassedThrough ] } >
2015-03-05 05:06:49 +00:00
B : box - none
2015-01-30 01:10:49 +00:00
< / D e m o T e x t >
< View
onTouchStart = { ( ) => this . props . onLog ( 'C unspecified touched' ) }
style = { styles . box } >
< DemoText style = { styles . text } >
C : unspecified
< / D e m o T e x t >
< / V i e w >
< View
2015-03-05 05:06:49 +00:00
pointerEvents = "auto"
2015-01-30 01:10:49 +00:00
onTouchStart = { ( ) => this . props . onLog ( 'C explicitly unspecified touched' ) }
style = { [ styles . box ] } >
< DemoText style = { [ styles . text ] } >
C : explicitly unspecified
< / D e m o T e x t >
< / V i e w >
< / V i e w >
< / V i e w >
) ;
}
} ) ;
var BoxOnlyExample = React . createClass ( {
render : function ( ) {
return (
< View
onTouchStart = { ( ) => this . props . onLog ( 'A unspecified touched' ) }
style = { styles . box } >
< DemoText style = { styles . text } >
A : unspecified
< / D e m o T e x t >
< View
2015-03-05 05:06:49 +00:00
pointerEvents = "box-only"
onTouchStart = { ( ) => this . props . onLog ( 'B box-only touched' ) }
2015-01-30 01:10:49 +00:00
style = { styles . box } >
< DemoText style = { styles . text } >
2015-03-05 05:06:49 +00:00
B : box - only
2015-01-30 01:10:49 +00:00
< / D e m o T e x t >
< View
onTouchStart = { ( ) => this . props . onLog ( 'C unspecified touched' ) }
style = { [ styles . box , styles . boxPassedThrough ] } >
< DemoText style = { [ styles . text , styles . textPassedThrough ] } >
C : unspecified
< / D e m o T e x t >
< / V i e w >
< View
2015-03-05 05:06:49 +00:00
pointerEvents = "auto"
2015-01-30 01:10:49 +00:00
onTouchStart = { ( ) => this . props . onLog ( 'C explicitly unspecified touched' ) }
style = { [ styles . box , styles . boxPassedThrough ] } >
< DemoText style = { [ styles . text , styles . textPassedThrough ] } >
C : explicitly unspecified
< / D e m o T e x t >
< / V i e w >
< / V i e w >
< / V i e w >
) ;
}
} ) ;
2015-05-12 21:22:22 +00:00
type ExampleClass = {
2016-03-08 20:38:52 +00:00
Component : ReactClass < any > ,
2015-05-12 21:22:22 +00:00
title : string ,
description : string ,
} ;
var exampleClasses : Array < ExampleClass > = [
2015-01-30 01:10:49 +00:00
{
Component : NoneExample ,
title : '`none`' ,
description : '`none` causes touch events on the container and its child components to pass through to the parent container.' ,
} ,
{
Component : BoxNoneExample ,
2015-03-05 05:06:49 +00:00
title : '`box-none`' ,
description : '`box-none` causes touch events on the container to pass through and will only detect touch events on its child components.' ,
2015-01-30 01:10:49 +00:00
} ,
{
Component : BoxOnlyExample ,
2015-03-05 05:06:49 +00:00
title : '`box-only`' ,
description : '`box-only` causes touch events on the container\'s child components to pass through and will only detect touch events on the container itself.' ,
2015-01-30 01:10:49 +00:00
}
] ;
var infoToExample = ( info ) => {
return {
title : info . title ,
description : info . description ,
render : function ( ) {
return < ExampleBox key = { info . title } Component = { info . Component } / > ;
} ,
} ;
} ;
var styles = StyleSheet . create ( {
text : {
fontSize : 10 ,
color : '#5577cc' ,
} ,
textPassedThrough : {
color : '#88aadd' ,
} ,
box : {
backgroundColor : '#aaccff' ,
borderWidth : 1 ,
borderColor : '#7799cc' ,
padding : 10 ,
margin : 5 ,
} ,
boxPassedThrough : {
borderColor : '#99bbee' ,
} ,
logText : {
fontSize : 9 ,
} ,
logBox : {
padding : 20 ,
margin : 10 ,
borderWidth : 0.5 ,
borderColor : '#f0f0f0' ,
backgroundColor : '#f9f9f9' ,
} ,
bottomSpacer : {
marginBottom : 100 ,
} ,
} ) ;
exports . framework = 'React' ;
exports . title = 'Pointer Events' ;
2015-09-15 21:46:54 +00:00
exports . description = 'Demonstrates the use of the pointerEvents prop of a ' +
'View to control how touches should be handled.' ;
2015-01-30 01:10:49 +00:00
exports . examples = exampleClasses . map ( infoToExample ) ;