-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1632 from parasharrajat/parasharrajat/tooltip
Added Tooltips to the report users' titles.
- Loading branch information
Showing
26 changed files
with
565 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import PropTypes from 'prop-types'; | ||
import {windowDimensionsPropTypes} from '../withWindowDimensions'; | ||
|
||
const propTypes = { | ||
// The text to display in the tooltip. | ||
text: PropTypes.string.isRequired, | ||
|
||
// Styles to be assigned to the Tooltip wrapper views | ||
containerStyle: PropTypes.object, | ||
|
||
// Children to wrap with Tooltip. | ||
children: PropTypes.node.isRequired, | ||
|
||
// Props inherited from withWindowDimensions | ||
...windowDimensionsPropTypes, | ||
|
||
// Any additional amount to manually adjust the horizontal position of the tooltip. | ||
// A positive value shifts the tooltip to the right, and a negative value shifts it to the left. | ||
shiftHorizontal: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), | ||
|
||
// Any additional amount to manually adjust the vertical position of the tooltip. | ||
// A positive value shifts the tooltip down, and a negative value shifts it up. | ||
shiftVertical: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), | ||
}; | ||
|
||
const defaultProps = { | ||
shiftHorizontal: 0, | ||
shiftVertical: 0, | ||
}; | ||
|
||
export { | ||
propTypes, | ||
defaultProps, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React, {memo} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {Animated, Text, View} from 'react-native'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
const propTypes = { | ||
// Style for Animation | ||
// eslint-disable-next-line react/forbid-prop-types | ||
animationStyle: PropTypes.object.isRequired, | ||
|
||
// Syle for Tooltip wrapper | ||
// eslint-disable-next-line react/forbid-prop-types | ||
tooltipWrapperStyle: PropTypes.object.isRequired, | ||
|
||
// Style for the text rendered inside tooltip | ||
// eslint-disable-next-line react/forbid-prop-types | ||
tooltipTextStyle: PropTypes.object.isRequired, | ||
|
||
// Style for the Tooltip pointer Wrapper | ||
// eslint-disable-next-line react/forbid-prop-types | ||
pointerWrapperStyle: PropTypes.object.isRequired, | ||
|
||
// Style for the Tooltip pointer | ||
// eslint-disable-next-line react/forbid-prop-types | ||
pointerStyle: PropTypes.object.isRequired, | ||
|
||
// Callback to set the Ref to the Tooltip | ||
setTooltipRef: PropTypes.func.isRequired, | ||
|
||
// Text to be shown in the tooltip | ||
text: PropTypes.string.isRequired, | ||
|
||
// Callback to be used to calulate the width and height of tooltip | ||
measureTooltip: PropTypes.func.isRequired, | ||
}; | ||
|
||
const defaultProps = {}; | ||
|
||
const TooltipRenderedOnPageBody = props => ReactDOM.createPortal( | ||
<Animated.View | ||
ref={props.setTooltipRef} | ||
onLayout={props.measureTooltip} | ||
style={[props.tooltipWrapperStyle, props.animationStyle]} | ||
> | ||
<Text style={props.tooltipTextStyle} numberOfLines={1}>{props.text}</Text> | ||
<View style={props.pointerWrapperStyle}> | ||
<View style={props.pointerStyle} /> | ||
</View> | ||
</Animated.View>, | ||
document.querySelector('body'), | ||
); | ||
|
||
TooltipRenderedOnPageBody.propTypes = propTypes; | ||
TooltipRenderedOnPageBody.defaultProps = defaultProps; | ||
TooltipRenderedOnPageBody.displayName = 'TooltipRenderedOnPageBody'; | ||
|
||
// Props will change frequently. | ||
// On every tooltip hover, we update the position in state which will result in re-rendering. | ||
// We also update the state on layout changes which will be triggered often. | ||
// There will be n number of tooltip components in the page. | ||
// Its good to memorize this one. | ||
export default memo(TooltipRenderedOnPageBody); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// We can't use the common component for the Tooltip as Web implementation uses DOM specific method to | ||
// render the View which is not present on the Mobile. | ||
import {propTypes, defaultProps} from './TooltipPropTypes'; | ||
|
||
/** | ||
* There is no native support for the Hover on the Mobile platform so we just return the enclosing childrens | ||
* @param {propTypes} props | ||
* @returns {ReactNodeLike} | ||
*/ | ||
const Tooltip = props => props.children; | ||
|
||
Tooltip.propTypes = propTypes; | ||
Tooltip.defaultProps = defaultProps; | ||
Tooltip.displayName = 'Tooltip'; | ||
export default Tooltip; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.