Skip to content

Commit

Permalink
Merge pull request #126 from galio-org/Alpha-1
Browse files Browse the repository at this point in the history
v0.6
  • Loading branch information
palingheorghe authored Sep 11, 2019
2 parents 639f86c + 743ceb5 commit 5822d2d
Show file tree
Hide file tree
Showing 17 changed files with 1,172 additions and 636 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "galio-framework",
"main": "src/index.js",
"version": "0.5.4",
"version": "0.6.0",
"files": [
"src/"
],
Expand Down
209 changes: 209 additions & 0 deletions src/Accordion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
import React, { useState, useEffect } from "react";
import {
Animated,
TouchableWithoutFeedback,
FlatList,
StyleSheet,
Dimensions
} from "react-native";
import PropTypes from "prop-types";

import Block from "./Block";
import Icon from "./Icon";
import Text from "./Text";
import GalioTheme from "./theme";

const { width } = Dimensions.get("screen");

//
function AccordionContent({ content, contentStyle }) {
return <Text style={[styles.content, contentStyle]}>{content}</Text>;
}

function AccordionHeader({
expanded,
expandedIcon,
headerStyle,
icon,
title,
chapterIcon
}) {
return (
<Block row middle style={[{ padding: 6 }, headerStyle]}>
{chapterIcon ? (
<Icon
name={chapterIcon.name}
family={chapterIcon.family}
size={chapterIcon.size || 14}
color={chapterIcon.color || GalioTheme.COLORS.PRIMARY}
style={chapterIcon.style || { marginRight: 5 }}
/>
) : null}
<Block row space="between" middle flex>
<Text size={16}>{title}</Text>
{expanded
? expandedIcon || (
<Icon
name="keyboard-arrow-up"
family="material"
size={16}
color={GalioTheme.COLORS.MUTED}
/>
)
: icon || (
<Icon
name="keyboard-arrow-down"
family="material"
size={16}
color={GalioTheme.COLORS.MUTED}
/>
)}
</Block>
</Block>
);
}

function AccordionAnimation({ children, style }) {
const [fade, setFade] = useState(new Animated.Value(0.3));

useEffect(() => {
Animated.timing(fade, {
toValue: 1,
duration: 400,
useNativeDriver: true
}).start();
});

return (
<Animated.View style={{ ...style, opacity: fade }}>
{children}
</Animated.View>
);
}

function AccordionItem({
expanded,
expandedIcon,
headerStyle,
contentStyle,
icon,
index,
item,
onAccordionClose,
onAccordionOpen,
setSelected
}) {
return (
<Block>
<TouchableWithoutFeedback
onPress={() => {
onAccordionOpen && !expanded && onAccordionOpen(item, index);
onAccordionClose && expanded && onAccordionClose(item, index);
setSelected(index);
}}
>
<Block>
<AccordionHeader
expanded={expanded}
expandedIcon={expandedIcon}
headerStyle={headerStyle}
icon={icon}
title={item.title}
chapterIcon={item.icon}
/>
</Block>
</TouchableWithoutFeedback>
{expanded ? (
<AccordionAnimation>
<AccordionContent
content={item.content}
contentStyle={contentStyle}
/>
</AccordionAnimation>
) : null}
</Block>
);
}

function Accordion({
theme,
dataArray,
icon,
expandedIcon,
headerStyle,
contentStyle,
opened,
onAccordionOpen,
onAccordionClose,
listStyle,
style
}) {
const [selected, setSelected] = useState(opened);

return (
<Block style={[styles.container, style]}>
<FlatList
data={dataArray}
extraData={selected}
style={listStyle}
keyExtractor={(item, index) => String(index)}
renderItem={({ item, index }) => (
<AccordionItem
key={String(index)}
expanded={selected === index}
expandedIcon={expandedIcon}
icon={icon}
headerStyle={headerStyle}
contentStyle={contentStyle}
onAccordionOpen={onAccordionOpen}
onAccordionClose={onAccordionClose}
item={item}
index={index}
setSelected={s => setSelected(selected === s ? undefined : s)}
/>
)}
/>
</Block>
);
}

Accordion.propTypes = {
theme: PropTypes.any,
dataArray: PropTypes.array,
opened: PropTypes.number,
listStyle: PropTypes.any,
style: PropTypes.any,
icon: PropTypes.any,
expandedIcon: PropTypes.any,
headerStyle: PropTypes.any,
contentStyle: PropTypes.any,
onAccordionClose: PropTypes.func,
onAccordionOpen: PropTypes.func,
};

Accordion.defaultProps = {
theme: GalioTheme,
opened: 0
};

const styles = StyleSheet.create({
container: {
flex: 1,
width: width * 0.8,
borderRadius: 16,
padding: 8,
shadowColor: "black",
shadowOffset: { width: 0, height: 1 },
shadowOpacity: 0.2,
shadowRadius: 4,
backgroundColor: 'white'
},
header: {
padding: 6
},
content: {
padding: 10
}
});

export default Accordion;
110 changes: 55 additions & 55 deletions src/Block.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,64 @@
import React, { Component } from 'react';
import React from 'react';
import { View, StyleSheet, SafeAreaView } from 'react-native';
import PropTypes from 'prop-types';
import GalioTheme, { withGalio } from './theme';

class Block extends Component {
render() {
const {
row,
flex,
center,
middle,
top,
bottom,
right,
left,
shadow,
space,
fluid,
height,
shadowColor,
card,
width,
safe,
children,
style,
styles,
...props
} = this.props;
function Block({
row,
flex,
center,
middle,
top,
bottom,
right,
left,
shadow,
space,
fluid,
height,
shadowColor,
card,
width,
safe,
children,
style,
styles,
...rest
}) {

const styleBlock = [
styles.block,
row && styles.row,
flex && { flex: flex === true ? 1 : flex },
center && styles.center,
middle && styles.middle,
top && styles.top,
bottom && styles.bottom,
right && styles.right,
left && styles.left,
space && { justifyContent: `space-${space}` },
shadow && styles.shadow,
fluid && styles.fluid,
card && styles.card,
height && { height },
width && { width },
shadowColor && { shadowColor },
style,
];

if (safe) {
return (
<SafeAreaView style={styleBlock} {...props}>
{children}
</SafeAreaView>
);
}
const styleBlock = [
styles.block,
row && styles.row,
flex && { flex: flex === true ? 1 : flex },
center && styles.center,
middle && styles.middle,
top && styles.top,
bottom && styles.bottom,
right && styles.right,
left && styles.left,
space && { justifyContent: `space-${space}` },
shadow && styles.shadow,
fluid && styles.fluid,
card && styles.card,
height && { height },
width && { width },
shadowColor && { shadowColor },
style,
];

if (safe) {
return (
<View {...props} style={styleBlock}>
<SafeAreaView style={styleBlock} {...rest}>
{children}
</View>
</SafeAreaView>
);
}

return (
<View style={styleBlock} {...rest}>
{children}
</View>
);
}

Block.defaultProps = {
Expand Down Expand Up @@ -143,7 +140,10 @@ const styles = theme =>
},
shadow: {
shadowColor: theme.COLORS.BLOCK,
shadowOffset: { width: 0, height: 3 },
shadowOffset: {
width: 0,
height: 3,
},
shadowOpacity: theme.SIZES.BLOCK_SHADOW_OPACITY,
shadowRadius: theme.SIZES.BLOCK_SHADOW_RADIUS,
elevation: theme.SIZES.ANDROID_ELEVATION,
Expand Down
Loading

0 comments on commit 5822d2d

Please sign in to comment.