Skip to content
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

Fix: change logic animated open collapse #128

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
36 changes: 30 additions & 6 deletions src/ui/collapse/collapse.body.component.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import * as React from 'react';
import { useRef, useState } from 'react';
import { Animated, Easing, LayoutChangeEvent } from 'react-native';
import { Animated, Easing, LayoutChangeEvent, StyleSheet } from 'react-native';
import { useDefaultProps } from '../../utilities/useDefaultProps';
import { Div } from '../div/div.component';

import { CollapseBodyProps } from './collapse.type';

const { styleCollapseAnimated } = StyleSheet.create({
styleCollapseAnimated: {
position: 'absolute',
zIndex: -1,
bottom: 0,
width: '100%',
},
});

const CollapseBody: React.FunctionComponent<CollapseBodyProps> = (
incomingProps
) => {
Expand Down Expand Up @@ -37,6 +46,11 @@ const CollapseBody: React.FunctionComponent<CollapseBodyProps> = (
outputRange: [0, bodySectionHeight],
});

const bodyOpacity = animatedController.interpolate({
inputRange: [0, 1],
outputRange: [0, 1],
});

React.useEffect(() => {
if (expanded) {
Animated.timing(animatedController, {
Expand All @@ -61,11 +75,21 @@ const CollapseBody: React.FunctionComponent<CollapseBodyProps> = (
};

return (
<Animated.View style={{ height: bodyHeight, overflow: 'hidden' }}>
<Div {...props} onLayout={onLayout}>
{children}
</Div>
</Animated.View>
<>
<Animated.View style={{ height: bodyHeight }} />
<Animated.View
style={[
{
opacity: bodyOpacity,
},
styleCollapseAnimated,
]}
>
<Div {...props} onLayout={onLayout}>
{children}
</Div>
</Animated.View>
</>
);
};

Expand Down
2 changes: 0 additions & 2 deletions src/ui/collapse/collapse.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { CollapseGroup } from './group.component';

const Collapse: CompoundedCollapse<CollapseProps> = (incomingProps) => {
const props = useDefaultProps('Collapse', incomingProps, {
bg: 'white',
flexDir: 'column',
flexWrap: 'nowrap',
rounded: 'md',
Expand Down Expand Up @@ -79,7 +78,6 @@ const Collapse: CompoundedCollapse<CollapseProps> = (incomingProps) => {
};

// Collapse.defaultProps = {
// bg: 'white',
// flexDir: 'column',
// flexWrap: 'nowrap',
// rounded: 'md',
Expand Down