forked from mattermost/mattermost-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Landscape support for both platforms (mattermost#909)
* Landscape support * Fix image rotation on Android * Fix landscape mode for login and login options * Fix previewer will receive props * Move device dimensions and others to redux * Fix unit tests * Include orientation and tablet in the store
- Loading branch information
1 parent
59762e4
commit 4995a76
Showing
57 changed files
with
672 additions
and
322 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. | ||
// See License.txt for license information. | ||
|
||
import {Dimensions} from 'react-native'; | ||
|
||
import {DeviceTypes} from 'app/constants'; | ||
|
||
export function calculateDeviceDimensions() { | ||
const {height, width} = Dimensions.get('window'); | ||
return { | ||
type: DeviceTypes.DEVICE_DIMENSIONS_CHANGED, | ||
data: { | ||
deviceHeight: height, | ||
deviceWidth: width | ||
} | ||
}; | ||
} | ||
|
||
export function connection(isOnline) { | ||
return async (dispatch, getState) => { | ||
dispatch({ | ||
type: DeviceTypes.CONNECTION_CHANGED, | ||
data: isOnline | ||
}, getState); | ||
}; | ||
} | ||
|
||
export function setStatusBarHeight(height = 20) { | ||
return { | ||
type: DeviceTypes.STATUSBAR_HEIGHT_CHANGED, | ||
data: height | ||
}; | ||
} | ||
|
||
export function setDeviceOrientation(orientation) { | ||
return { | ||
type: DeviceTypes.DEVICE_ORIENTATION_CHANGED, | ||
data: orientation | ||
}; | ||
} | ||
|
||
export function setDeviceAsTablet() { | ||
return { | ||
type: DeviceTypes.DEVICE_TYPE_CHANGED, | ||
data: true | ||
}; | ||
} | ||
|
||
export default { | ||
calculateDeviceDimensions, | ||
connection, | ||
setDeviceOrientation, | ||
setDeviceAsTablet, | ||
setStatusBarHeight | ||
}; |
This file was deleted.
Oops, something went wrong.
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
93 changes: 93 additions & 0 deletions
93
app/components/channel_drawer/drawer_swipper/drawer_swiper.js
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,93 @@ | ||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. | ||
// See License.txt for license information. | ||
|
||
import React, {PureComponent} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Swiper from 'react-native-swiper'; | ||
|
||
import {changeOpacity} from 'app/utils/theme'; | ||
|
||
export default class DrawerSwiper extends PureComponent { | ||
static propTypes = { | ||
children: PropTypes.node.isRequired, | ||
deviceHeight: PropTypes.number.isRequired, | ||
deviceWidth: PropTypes.number.isRequired, | ||
isLandscape: PropTypes.bool.isRequired, | ||
onPageSelected: PropTypes.func, | ||
openDrawerOffset: PropTypes.number, | ||
showTeams: PropTypes.bool.isRequired, | ||
theme: PropTypes.object.isRequired | ||
}; | ||
|
||
static defaultProps = { | ||
onPageSelected: () => true, | ||
openDrawerOffset: 0 | ||
}; | ||
|
||
state = { | ||
index: 1 | ||
}; | ||
|
||
componentWillReceiveProps(nextProps) { | ||
if (this.refs.swiper) { | ||
if (nextProps.openDrawerOffset !== this.props.openDrawerOffset || nextProps.isLandscape !== this.props.isLandscape) { | ||
this.refs.swiper.initialRender = true; | ||
if (this.state.index === 1) { | ||
this.resetPage(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
swiperPageSelected = (e, state, context) => { | ||
this.props.onPageSelected(context.state.index); | ||
this.setState({index: context.state.index}); | ||
}; | ||
|
||
showTeamsPage = () => { | ||
this.refs.swiper.scrollBy(-1, true); | ||
}; | ||
|
||
resetPage = () => { | ||
this.refs.swiper.scrollBy(1, false); | ||
}; | ||
|
||
render() { | ||
const { | ||
children, | ||
deviceHeight, | ||
deviceWidth, | ||
openDrawerOffset, | ||
showTeams, | ||
theme | ||
} = this.props; | ||
|
||
const pagination = {bottom: 0}; | ||
if (showTeams) { | ||
pagination.bottom = 0; | ||
} | ||
|
||
return ( | ||
<Swiper | ||
ref='swiper' | ||
horizontal={true} | ||
loop={false} | ||
index={this.state.index} | ||
onMomentumScrollEnd={this.swiperPageSelected} | ||
paginationStyle={[{position: 'absolute'}, pagination]} | ||
width={deviceWidth - openDrawerOffset} | ||
height={deviceHeight} | ||
style={{backgroundColor: theme.sidebarBg}} | ||
activeDotColor={theme.sidebarText} | ||
dotColor={changeOpacity(theme.sidebarText, 0.5)} | ||
removeClippedSubviews={true} | ||
automaticallyAdjustContentInsets={true} | ||
scrollEnabled={showTeams} | ||
showsPagination={showTeams} | ||
keyboardShouldPersistTaps={'always'} | ||
> | ||
{children} | ||
</Swiper> | ||
); | ||
} | ||
} |
Oops, something went wrong.