Skip to content

Commit

Permalink
fix: format with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
pwysowski committed Apr 10, 2020
1 parent b3e53fc commit 0d09fad
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 91 deletions.
76 changes: 36 additions & 40 deletions src/StickyParallaxHeader.js
Expand Up @@ -67,42 +67,42 @@ class StickyParallaxHeader extends Component {
if (y > 0 && y < snapToEdgeTreshold) {
return constants.isAndroid
? this.setState(
{
isFolded: false
},
scrollNode.scrollTo({ x: 0, y: 0, animated: true })
)
{
isFolded: false
},
scrollNode.scrollTo({ x: 0, y: 0, animated: true })
)
: timing(snapToEdgeAnimatedValue, {
toValue: { x: 0, y: 0 },
duration: 400,
easing: Easing.out(Easing.cubic),
useNativeDriver: true
}).start(() => {
snapToEdgeAnimatedValue.removeListener(id)
this.setState({
isFolded: false
toValue: { x: 0, y: 0 },
duration: 400,
easing: Easing.out(Easing.cubic),
useNativeDriver: true
}).start(() => {
snapToEdgeAnimatedValue.removeListener(id)
this.setState({
isFolded: false
})
})
})
}
if (y >= snapToEdgeTreshold && y < scrollHeight) {
return constants.isAndroid
? this.setState(
{
isFolded: true
},
scrollNode.scrollTo({ x: 0, y: scrollHeight, animated: true })
)
{
isFolded: true
},
scrollNode.scrollTo({ x: 0, y: scrollHeight, animated: true })
)
: timing(snapToEdgeAnimatedValue, {
toValue: { x: 0, y: scrollHeight },
duration: 400,
easing: Easing.out(Easing.cubic),
useNativeDriver: true
}).start(() => {
snapToEdgeAnimatedValue.removeListener(id)
this.setState({
isFolded: true
toValue: { x: 0, y: scrollHeight },
duration: 400,
easing: Easing.out(Easing.cubic),
useNativeDriver: true
}).start(() => {
snapToEdgeAnimatedValue.removeListener(id)
this.setState({
isFolded: true
})
})
})
}
}

Expand Down Expand Up @@ -161,7 +161,7 @@ class StickyParallaxHeader extends Component {
const isArray = Array.isArray(headerStyle)
const arrayHeaderStyle = {}
if (isArray) {
headerStyle.map(el => Object.assign(arrayHeaderStyle, el))
headerStyle.map((el) => Object.assign(arrayHeaderStyle, el))
}

return (
Expand Down Expand Up @@ -280,7 +280,7 @@ class StickyParallaxHeader extends Component {
const isArray = Array.isArray(headerStyle)
const arrayHeaderStyle = {}
if (isArray) {
headerStyle.map(el => Object.assign(arrayHeaderStyle, el))
headerStyle.map((el) => Object.assign(arrayHeaderStyle, el))
}

const shouldRenderTabs = tabs && tabs.length > 0
Expand Down Expand Up @@ -320,26 +320,22 @@ class StickyParallaxHeader extends Component {
}
)}
>
<View style={{ height: parallaxHeight }} onLayout={e => this.onLayout(e)}>
<View style={{ height: parallaxHeight }} onLayout={(e) => this.onLayout(e)}>
<View
style={[
styles.overScrollPadding,
{
backgroundColor: isArray
? arrayHeaderStyle.backgroundColor
: headerStyle?.backgroundColor
backgroundColor: isArray ? arrayHeaderStyle.backgroundColor : headerStyle?.backgroundColor
}
]}
/>
{backgroundImage
? this.renderImageBackground(scrollHeight)
: this.renderPlainBackground(scrollHeight)}
{backgroundImage ? this.renderImageBackground(scrollHeight) : this.renderPlainBackground(scrollHeight)}
{this.renderForeground(scrollHeight)}
</View>
{shouldRenderTabs && this.renderTabs()}
<ScrollableTabView
initialPage={initialPage}
onChangeTab={i => this.onChangeTabHandler(i)}
onChangeTab={(i) => this.onChangeTabHandler(i)}
tabs={tabs}
page={currentPage}
swipedPage={this.goToPage}
Expand All @@ -348,8 +344,8 @@ class StickyParallaxHeader extends Component {
isHeaderFolded={isFolded}
>
{!tabs && children}
{tabs
&& tabs.map(item => (
{tabs &&
tabs.map((item) => (
<View
tabLabel={item.title}
key={item.title}
Expand Down
30 changes: 11 additions & 19 deletions src/components/ScrollableTabBar/ScrollableTabBar.js
Expand Up @@ -13,23 +13,21 @@ class ScrollableTabBar extends React.PureComponent {
super(props)
this.currentXPosition = 0
this.state = {
tabUnderlineWidth: props.tabs.map(_ => 0),
tabUnderlineWidth: props.tabs.map((_) => 0),
activeTab: this.props.activeTab
}
}
componentDidUpdate(prevProps, prevState){

componentDidUpdate(prevProps, prevState) {
const { activeTab } = this.state
if(prevState.activeTab !== activeTab){
if (prevState.activeTab !== activeTab) {
this.scrollToTab(activeTab)
}
}

static getDerivedStateFromProps(nextProps, prevState){
if(nextProps.activeTab !== prevState.activeTab)
return {activeTab: nextProps.activeTab}
else
return null

static getDerivedStateFromProps(nextProps, prevState) {
if (nextProps.activeTab !== prevState.activeTab) return { activeTab: nextProps.activeTab }
else return null
}

adjustPrevious = (page) => {
Expand Down Expand Up @@ -123,8 +121,8 @@ class ScrollableTabBar extends React.PureComponent {
<ScrollView
style={styles.nestedStyle}
contentContainerStyle={styles.contentContainer}
ref={r => (this.scrollView = r)}
onScrollEndDrag={event => (this.currentXPosition = event.nativeEvent.contentOffset.x)}
ref={(r) => (this.scrollView = r)}
onScrollEndDrag={(event) => (this.currentXPosition = event.nativeEvent.contentOffset.x)}
vertical={false}
horizontal
bounces={false}
Expand All @@ -143,13 +141,7 @@ class ScrollableTabBar extends React.PureComponent {
activeOpacity={0.9}
onPress={() => this.goToPage(page)}
>
<View
style={[
styles.tabContainer,
tabTextContainerStyle,
isTabActive && tabTextContainerActiveStyle
]}
>
<View style={[styles.tabContainer, tabTextContainerStyle, isTabActive && tabTextContainerActiveStyle]}>
<Text
// eslint-disable-next-line no-return-assign
onLayout={({
Expand Down
61 changes: 29 additions & 32 deletions src/components/ScrollableTabView/ScrollableTabView.js
Expand Up @@ -40,26 +40,22 @@ class ScrollableTabView extends React.Component {
scrollXIOS.addListener(({ value }) => callListeners(value / deviceWidth))
}

static getDerivedStateFromProps(nextProps, prevState){
static getDerivedStateFromProps(nextProps, prevState) {
let update = {}

if(nextProps.children !== prevState.children)
update.children = nextProps.children
if (nextProps.children !== prevState.children) update.children = nextProps.children

if(nextProps.page >=0 && nextProps.page !== prevState.currentPage)
update.currentPage = nextProps.page
if (nextProps.page >= 0 && nextProps.page !== prevState.currentPage) update.currentPage = nextProps.page

return Object.keys(update).length ? update : null;
return Object.keys(update).length ? update : null
}
componentDidUpdate(prevProps, prevState){

componentDidUpdate(prevProps, prevState) {
const { children, currentPage } = this.state

if(prevState.children !== children)
this.updateSceneKeys({ page: currentPage, children: children })

if(prevState.currentPage !== currentPage)
this.goToPage(currentPage)
if (prevState.children !== children) this.updateSceneKeys({ page: currentPage, children: children })

if (prevState.currentPage !== currentPage) this.goToPage(currentPage)
}

componentWillUnmount() {
Expand Down Expand Up @@ -94,8 +90,8 @@ class ScrollableTabView extends React.Component {
const { scrollRef, scrollHeight, isHeaderFolded } = this.props

return (
isHeaderFolded
&& scrollRef.getNode().scrollTo({
isHeaderFolded &&
scrollRef.getNode().scrollTo({
y: scrollHeight,
duration: 1000
})
Expand All @@ -113,24 +109,25 @@ class ScrollableTabView extends React.Component {
})
}

composeScenes = () => this.children().map((child, idx) => {
const key = this.makeSceneKey(child, idx)
const { currentPage, containerWidth, sceneKeys } = this.state

return (
<SceneComponent
key={child.key}
shouldUpdated={this.shouldRenderSceneKey(idx, currentPage)}
style={{ width: containerWidth }}
>
{this.keyExists(sceneKeys, key) ? child : null}
</SceneComponent>
)
})
composeScenes = () =>
this.children().map((child, idx) => {
const key = this.makeSceneKey(child, idx)
const { currentPage, containerWidth, sceneKeys } = this.state

return (
<SceneComponent
key={child.key}
shouldUpdated={this.shouldRenderSceneKey(idx, currentPage)}
style={{ width: containerWidth }}
>
{this.keyExists(sceneKeys, key) ? child : null}
</SceneComponent>
)
})

makeSceneKey = (child, idx) => `${child.props.tabLabel}_${idx}`

keyExists = (sceneKeys, key) => sceneKeys.find(sceneKey => key === sceneKey)
keyExists = (sceneKeys, key) => sceneKeys.find((sceneKey) => key === sceneKey)

// eslint-disable-next-line max-len
shouldRenderSceneKey = (idx, currentPageKey) => idx < currentPageKey + 1 && idx > currentPageKey - 1
Expand All @@ -155,7 +152,7 @@ class ScrollableTabView extends React.Component {
animatedValue.removeAllListeners = removeAllListeners
/* eslint-disable no-param-reassign */

return value => listeners.forEach(listener => listener({ value }))
return (value) => listeners.forEach((listener) => listener({ value }))
}

newSceneKeys = ({ previousKeys = [], currentPage = 0, children = this.props.children }) => {
Expand Down Expand Up @@ -213,7 +210,7 @@ class ScrollableTabView extends React.Component {
})
}

children = (children = this.props.children) => React.Children.map(children, child => child)
children = (children = this.props.children) => React.Children.map(children, (child) => child)

renderScrollableContent() {
const scenes = this.composeScenes()
Expand Down

0 comments on commit 0d09fad

Please sign in to comment.