Skip to content

Added animation type for RN Modal #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions src/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ const DEFAULT_DISPLAY_INSETS = {
right: 24,
};

const computeDisplayInsets = insetsFromProps =>
const computeDisplayInsets = (insetsFromProps) =>
Object.assign({}, DEFAULT_DISPLAY_INSETS, insetsFromProps);

const invertPlacement = placement => {
const invertPlacement = (placement) => {
switch (placement) {
case 'top':
return 'bottom';
Expand Down Expand Up @@ -75,6 +75,7 @@ class Tooltip extends Component {
useReactNativeModal: true,
topAdjustment: 0,
accessible: true,
animationType: 'fade',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the current default is 'none' could you update this so it is backward compatible?

};

static propTypes = {
Expand Down Expand Up @@ -105,6 +106,7 @@ class Tooltip extends Component {
useReactNativeModal: PropTypes.bool,
topAdjustment: PropTypes.number,
accessible: PropTypes.bool,
animationType: PropTypes.oneOf(['none', 'fade', 'slide']),
};

constructor(props) {
Expand Down Expand Up @@ -208,7 +210,7 @@ class Tooltip extends Component {
return null;
}

updateWindowDims = dims => {
updateWindowDims = (dims) => {
this.setState(
{
windowDims: dims.window,
Expand Down Expand Up @@ -237,15 +239,15 @@ class Tooltip extends Component {
);
};

measureContent = e => {
measureContent = (e) => {
const { width, height } = e.nativeEvent.layout;
const contentSize = new Size(width, height);
this.setState({ contentSize }, () => {
this.computeGeometry();
});
};

onChildMeasurementComplete = rect => {
onChildMeasurementComplete = (rect) => {
this.setState(
{
childRect: rect,
Expand All @@ -272,7 +274,7 @@ class Tooltip extends Component {
(x, y, width, height, pageX, pageY) => {
const childRect = new Rect(pageX, pageY, width, height);
if (
Object.values(childRect).every(value => value !== undefined)
Object.values(childRect).every((value) => value !== undefined)
) {
this.onChildMeasurementComplete(childRect);
} else {
Expand Down Expand Up @@ -300,13 +302,8 @@ class Tooltip extends Component {

computeGeometry = () => {
const { arrowSize, childContentSpacing } = this.props;
const {
childRect,
contentSize,
displayInsets,
placement,
windowDims,
} = this.state;
const { childRect, contentSize, displayInsets, placement, windowDims } =
this.state;

const options = {
displayInsets,
Expand Down Expand Up @@ -446,6 +443,7 @@ class Tooltip extends Component {
isVisible,
useReactNativeModal,
modalComponent,
animationType,
} = this.props;

const hasChildren = React.Children.count(children) > 0;
Expand All @@ -456,6 +454,7 @@ class Tooltip extends Component {
<React.Fragment>
{useReactNativeModal ? (
<ModalComponent
animationType={this.props.animationType}
transparent
visible={showTooltip}
onRequestClose={this.props.onClose}
Expand Down