UNPKG

react-native-1app

Version:

68 lines (61 loc) 1.47 kB
'use strict'; import React, { Component } from 'react'; import { StyleSheet, TouchableOpacity,Platform,View } from 'react-native'; export default class EdiTouchableOpacity extends Component { ativo = true; isElevation(elevation){ if (elevation) { return Platform.select({ ios: { shadowColor: 'black', shadowOffset: { width: 0, height: 2 }, shadowOpacity: (0.5/elevation), shadowRadius: (2/elevation), // shadowOffset: { // height: 1, // width: 0 // } }, android: { elevation: (5/elevation), } }); } return null; } render() { return ( <TouchableOpacity {...this.props} style={[styles.view,this.isElevation(this.props.elevation),this.props.style]} disabled={this.props.disabled} onPress={ () => { if(this.props.onPress && this.ativo){ this.props.onPress(); this.ativo = false; setTimeout( () =>{ this.ativo = true; }, 500); }else{ setTimeout( () =>{ this.ativo = true; }, 500); } } }> {this.props.children} </TouchableOpacity> ); } } let styles = StyleSheet.create({ view:{} }) EdiTouchableOpacity.defaultProps={ onPress:()=>console.log("NOT onPress"), style:{}, disabled:false, elevation:null }