import React from "react" import * as antd from "antd" import classnames from "classnames" import { ActionSheet } from "antd-mobile" import { Motion, spring } from "react-motion" import { Icons, createIconRender } from "components/Icons" import { WithPlayerContext, Context } from "contexts/WithPlayerContext" import { QuickNavMenuItems, QuickNavMenu } from "components/Layout/quickNav" import PlayerView from "pages/@mobile-views/player" import CreatorView from "pages/@mobile-views/creator" import "./index.less" const tourSteps = [ { title: "Open quick nav", description: "Xd", ref: React.createRef(), }, { title: "Account button", description: "Xd", ref: React.createRef(), } ] const openPlayerView = () => { app.DrawerController.open("player", PlayerView) } const openCreator = () => { app.DrawerController.open("creator", CreatorView, { props: { bodyStyle: { minHeight: "unset", height: "50vh" } } }) } const PlayerButton = (props) => { React.useEffect(() => { openPlayerView() }, []) return
{ props.playback === "playing" ? : }
} const AccountButton = React.forwardRef((props, ref) => { const user = app.userData const ActionSheetRef = React.useRef() const handleClick = () => { if (!user) { return app.navigation.goAuth() } return app.navigation.goToAccount() } const handleHold = () => { ActionSheetRef.current = ActionSheet.show({ actions: [ { key: "settings", text: <> Settings, onClick: () => { app.navigation.goToSettings() ActionSheetRef.current.close() } }, { key: "account", text: <> Account, onClick: () => { app.navigation.goToAccount() ActionSheetRef.current.close() } }, { key: "logout", text: <> Logout, danger: true, onClick: () => { app.eventBus.emit("app.logout_request") ActionSheetRef.current.close() } } ] }) } return
{ user ? : createIconRender("Login") }
}) export default (props) => { return } export class BottomBar extends React.Component { static contextType = Context state = { visible: false, quickNavVisible: false, render: null, tourOpen: false, } busEvents = { "runtime.crash": () => { this.toggleVisibility(false) } } refs = { homeBtn: React.createRef(), accountBtn: React.createRef(), } componentDidMount = () => { this.interface = app.layout.bottom_bar = { toggleVisible: this.toggleVisibility, isVisible: () => this.state.visible, render: (fragment) => { this.setState({ render: fragment }) }, clear: () => { this.setState({ render: null }) }, toggleTour: () => { this.setState({ tourOpen: !this.state.tourOpen }) }, } setTimeout(() => { this.setState({ visible: true }) }, 10) // Register bus events Object.keys(this.busEvents).forEach((key) => { app.eventBus.on(key, this.busEvents[key]) }) } componentWillUnmount = () => { delete window.app.layout.bottom_bar // Unregister bus events Object.keys(this.busEvents).forEach((key) => { app.eventBus.off(key, this.busEvents[key]) }) } toggleVisibility = (to) => { if (typeof to === "undefined") { to = !this.state.visible } this.setState({ visible: to }) } handleItemClick = (item) => { if (item.dispatchEvent) { app.eventBus.emit(item.dispatchEvent) } else if (item.location) { app.location.push(item.location) } } handleNavTouchStart = (e) => { this._navTouchStart = setTimeout(() => { this.setState({ quickNavVisible: true }) if (app.cores.haptics?.vibrate) { app.cores.haptics.vibrate(80) } // remove the timeout this._navTouchStart = null }, 400) } handleNavTouchEnd = (event) => { if (this._lastHovered) { this._lastHovered.classList.remove("hover") } if (this._navTouchStart) { clearTimeout(this._navTouchStart) this._navTouchStart = null return false } this.setState({ quickNavVisible: false }) // get cords of the touch const x = event.changedTouches[0].clientX const y = event.changedTouches[0].clientY // get the element at the touch const element = document.elementFromPoint(x, y) // get the closest element with the attribute const closest = element.closest(".quick-nav_item") if (!closest) { return false } const item = QuickNavMenuItems.find((item) => { return item.id === closest.getAttribute("quicknav-item") }) if (!item) { return false } if (item.location) { app.location.push(item.location) if (app.cores.haptics?.vibrate) { app.cores.haptics.vibrate([40, 80]) } } } handleNavTouchMove = (event) => { // check if the touch is hovering a quicknav item const x = event.changedTouches[0].clientX const y = event.changedTouches[0].clientY // get the element at the touch const element = document.elementFromPoint(x, y) // get the closest element with the attribute const closest = element.closest("[quicknav-item]") if (!closest) { if (this._lastHovered) { this._lastHovered.classList.remove("hover") } this._lastHovered = null return false } if (this._lastHovered !== closest) { if (this._lastHovered) { this._lastHovered.classList.remove("hover") } this._lastHovered = closest closest.classList.add("hover") if (app.cores.haptics?.vibrate) { app.cores.haptics.vibrate(40) } } } toggleTour = (to) => { if (typeof to === "undefined") { to = !this.state.tourOpen } this.setState({ tourOpen: to }) } render() { if (this.state.render) { return
{this.state.render}
} const heightValue = this.state.visible ? Number(app.cores.style.defaultVar("bottom-bar-height").replace("px", "")) : 0 return <> {({ y, height }) =>
{createIconRender("PlusCircle")}
{ this.context.currentManifest &&
}
{createIconRender("Search")}
}
} }