react-native-walkthrough-tooltip
Advanced tools
Comparing version
{ | ||
"name": "react-native-walkthrough-tooltip", | ||
"version": "0.6.0-alpha.1", | ||
"version": "0.6.0-alpha.2", | ||
"description": "An inline wrapper for calling out React Native components via tooltip", | ||
@@ -5,0 +5,0 @@ "main": "src/tooltip.js", |
@@ -24,2 +24,3 @@ import React, { Component } from 'react'; | ||
const SCREEN_HEIGHT = Dimensions.get('window').height; | ||
@@ -282,2 +283,6 @@ const SCREEN_WIDTH = Dimensions.get('window').width; | ||
} | ||
if (!this.props.children) { | ||
this.mockChildRect(); | ||
} | ||
}; | ||
@@ -315,61 +320,67 @@ | ||
} else { | ||
// mock the placement of a child to compute geom | ||
let rectForChildlessPlacement = { ...this.state.childRect }; | ||
let placementPadding = DEFAULT_PADDING; | ||
this.mockChildRect(); | ||
} | ||
} | ||
}; | ||
const { childlessPlacementPadding, placement } = this.props; | ||
// handle percentages | ||
if (typeof childlessPlacementPadding === 'string') { | ||
const isPercentage = | ||
childlessPlacementPadding.substring(childlessPlacementPadding.length - 1) === '%'; | ||
const paddingValue = parseFloat(childlessPlacementPadding, 10); | ||
const verticalPlacement = placement === 'top' || placement === 'bottom'; | ||
mockChildRect = () => { | ||
// mock the placement of a child to compute geom | ||
let rectForChildlessPlacement = { ...this.state.childRect }; | ||
let placementPadding = DEFAULT_PADDING; | ||
if (isPercentage) { | ||
placementPadding = | ||
(paddingValue / 100.0) * (verticalPlacement ? SCREEN_HEIGHT : SCREEN_WIDTH); | ||
} else { | ||
placementPadding = paddingValue; | ||
} | ||
} else { | ||
placementPadding = childlessPlacementPadding; | ||
} | ||
const { childlessPlacementPadding, placement } = this.props; | ||
if (Number.isNaN(placementPadding)) { | ||
throw new Error('[Tooltip] Invalid value passed to childlessPlacementPadding'); | ||
} | ||
// handle percentages | ||
if (typeof childlessPlacementPadding === 'string') { | ||
const isPercentage = | ||
childlessPlacementPadding.substring(childlessPlacementPadding.length - 1) === '%'; | ||
const paddingValue = parseFloat(childlessPlacementPadding, 10); | ||
const verticalPlacement = placement === 'top' || placement === 'bottom'; | ||
const CENTER_X = SCREEN_WIDTH / 2; | ||
const CENTER_Y = SCREEN_HEIGHT / 2; | ||
if (isPercentage) { | ||
placementPadding = | ||
(paddingValue / 100.0) * (verticalPlacement ? SCREEN_HEIGHT : SCREEN_WIDTH); | ||
} else { | ||
placementPadding = paddingValue; | ||
} | ||
} else { | ||
placementPadding = childlessPlacementPadding; | ||
} | ||
switch (placement) { | ||
case 'bottom': | ||
rectForChildlessPlacement = new Rect(CENTER_X, SCREEN_HEIGHT - placementPadding, 0, 0); | ||
break; | ||
case 'left': | ||
rectForChildlessPlacement = new Rect(placementPadding, CENTER_Y, 0, 0); | ||
break; | ||
case 'right': | ||
rectForChildlessPlacement = new Rect(SCREEN_WIDTH - placementPadding, CENTER_Y, 0, 0); | ||
break; | ||
default: | ||
case 'top': | ||
rectForChildlessPlacement = new Rect(CENTER_X, placementPadding, 0, 0); | ||
break; | ||
} | ||
if (Number.isNaN(placementPadding)) { | ||
throw new Error('[Tooltip] Invalid value passed to childlessPlacementPadding'); | ||
} | ||
this.setState( | ||
{ | ||
childRect: rectForChildlessPlacement, | ||
readyToComputeGeom: true, | ||
}, | ||
() => { | ||
this.isMeasuringChild = false; | ||
this.finishMeasurements(); | ||
}, | ||
); | ||
} | ||
const CENTER_X = SCREEN_WIDTH / 2; | ||
const CENTER_Y = SCREEN_HEIGHT / 2; | ||
switch (placement) { | ||
case 'bottom': | ||
rectForChildlessPlacement = new Rect(CENTER_X, SCREEN_HEIGHT - placementPadding, 0, 0); | ||
break; | ||
case 'left': | ||
rectForChildlessPlacement = new Rect(placementPadding, CENTER_Y, 0, 0); | ||
break; | ||
case 'right': | ||
rectForChildlessPlacement = new Rect(SCREEN_WIDTH - placementPadding, CENTER_Y, 0, 0); | ||
break; | ||
default: | ||
case 'top': | ||
rectForChildlessPlacement = new Rect(CENTER_X, placementPadding, 0, 0); | ||
break; | ||
} | ||
}; | ||
this.setState( | ||
{ | ||
childRect: rectForChildlessPlacement, | ||
readyToComputeGeom: true, | ||
}, | ||
() => { | ||
this.isMeasuringChild = false; | ||
this.finishMeasurements(); | ||
}, | ||
); | ||
} | ||
_doComputeGeometry = ({ contentSize }) => { | ||
@@ -624,3 +635,3 @@ const geom = this.computeGeometry({ contentSize }); | ||
styles.container, | ||
sizeAvailable && measurementsFinished && styles.containerVisible, | ||
sizeAvailable && measurementsFinished && styles.containerVisible | ||
]} | ||
@@ -627,0 +638,0 @@ > |
801
0.75%37822
-0.17%