Repository navigation
Expand file tree
/
Copy pathdevice.js
More file actions
53 lines (50 loc) · 1.6 KB
/
Copy pathdevice.js
File metadata and controls
53 lines (50 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { fromJS } from 'immutable'
import { handleActions } from 'redux-actions'
import { screen } from '../utils'
// Constants
// --------------------------------------------------
export const SHOW_SET = 'SHOW_SET'
// Actions
// ---------------------------------.3-----------------
//横竖屏切换,使用
export const setShow = (params = {}, cb = () => {}) => async dispatch => {
await dispatch({
type: SHOW_SET,
payload: params,
})
cb && cb()
}
const initialState = fromJS({
device: {
orientation:
screen.deviceHeight > screen.deviceWidth ? 'PORTRAIT' : 'LANDSCAPE',
width: screen.getScreenWidth(),
height: screen.getScreenHeight(),
},
})
export default handleActions(
{
[`${SHOW_SET}`]: (state, { payload }) => {
let device = state.toJS().device
let deviceWidth = screen.getScreenWidth()
let deviceHeight = screen.getScreenHeight()
if (payload.orientation) {
device.orientation = payload.orientation
if (payload.orientation === 'LANDSCAPE') {
device.width = deviceWidth > deviceHeight ? deviceWidth : deviceHeight
device.height =
deviceWidth < deviceHeight ? deviceWidth : deviceHeight
} else {
device.width = deviceWidth < deviceHeight ? deviceWidth : deviceHeight
device.height =
deviceWidth > deviceHeight ? deviceWidth : deviceHeight
}
}
return state.setIn(['device'], fromJS(device))
},
// [REHYDRATE]: (state, { payload }) => {
// return payload && payload.device ? fromJS(payload.device) : state
// },
},
initialState,
)