Skip to content

Commit

Permalink
Manage the menu button using messages + prevent re-mounting on resize (
Browse files Browse the repository at this point in the history
…#651)

Changes:

- Send displayMenuButton (Boolean) to the current app.
- Deprecate `menuPanel` in favor of `requestMenu: true` to display the menu panel from an app.
- Prevent re-mounting the children of Wrapper on resize.
  • Loading branch information
bpierre authored Mar 19, 2019
1 parent bb02b8b commit 694a70b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
34 changes: 28 additions & 6 deletions src/Wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ class Wrapper extends React.PureComponent {
walletWeb3: null,
}

componentDidUpdate(prevProps) {
this.updateAutoClosingPanel(prevProps)
}

state = {
appInstance: {},
menuPanelOpened: !this.props.autoClosingPanel,
Expand All @@ -74,10 +70,26 @@ class Wrapper extends React.PureComponent {
queuedNotifications: [],
}

componentDidUpdate(prevProps) {
this.updateAutoClosingPanel(prevProps)
}

updateAutoClosingPanel(prevProps) {
const { autoClosingPanel } = this.props
if (autoClosingPanel !== prevProps.autoClosingPanel) {
this.setState({ menuPanelOpened: !autoClosingPanel })
this.sendDisplayMenuButtonStatus()
}
}

sendDisplayMenuButtonStatus() {
const { autoClosingPanel } = this.props
if (this.appIFrame) {
this.appIFrame.sendMessage({
from: 'wrapper',
name: 'displayMenuButton',
value: autoClosingPanel,
})
}
}

Expand All @@ -89,9 +101,11 @@ class Wrapper extends React.PureComponent {
const { historyPush, locator } = this.props
historyPush(getAppPath({ dao: locator.dao, instanceId, params }))
}

handleAppIFrameRef = appIFrame => {
this.appIFrame = appIFrame
}

handleAppIFrameLoad = async event => {
const {
apps,
Expand All @@ -107,15 +121,23 @@ class Wrapper extends React.PureComponent {
}

await wrapper.connectAppIFrame(event.target, instanceId)

this.appIFrame.sendMessage({
from: 'wrapper',
name: 'ready',
value: true,
})
this.sendDisplayMenuButtonStatus()
}
handleAppMessage = ({ data: { name, value } }) => {
if (name === 'menuPanel') {
this.setState({ menuPanelOpened: Boolean(value) })
if (
// “menuPanel: Boolean” is deprecated but still supported for a while if
// value is `true`.
name === 'menuPanel' ||
// “requestMenu: true” should now be used.
name === 'requestMenu'
) {
this.setState({ menuPanelOpened: value === true })
}
}
handleMenuPanelOpen = () => {
Expand Down
11 changes: 6 additions & 5 deletions src/components/MenuPanel/SwipeContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ class SwipeContainer extends React.Component {
onMenuPanelOpen,
width,
} = this.props
const oneThirdWindowWidth = width / 3

if (!enabled) {
return <Container>{children(Number(menuPanelOpened))}</Container>
}
const oneThirdWindowWidth = width / 3

return (
<Gesture passive={{ passive: false }} mouse={false}>
<Gesture passive={{ passive: false }} mouse={false} touch={enabled}>
{({
delta: [xDelta, yDelta],
direction: [xDir, yDir],
Expand All @@ -45,6 +42,10 @@ class SwipeContainer extends React.Component {
initial: [xInitial],
xy: [x],
}) => {
if (!enabled) {
return <Container>{children(Number(menuPanelOpened))}</Container>
}

if (
!down &&
this._previousProgress > 0 &&
Expand Down

0 comments on commit 694a70b

Please sign in to comment.