diff options
| author | taehoon <th.dev91@gmail.com> | 2019-09-19 13:59:34 -0400 |
|---|---|---|
| committer | taehoon <th.dev91@gmail.com> | 2019-09-20 11:29:29 -0400 |
| commit | d6a941a128f37a2d04f5e60ad21037c2c5efcfa3 (patch) | |
| tree | 07e7093e8ad4a3af99e9749593a17e2cbc6f87aa /src/components/mobile_post_status_button | |
| parent | 0c8038d4f610bd7260b920e6fb55a8ea0341d291 (diff) | |
rename component
Diffstat (limited to 'src/components/mobile_post_status_button')
| -rw-r--r-- | src/components/mobile_post_status_button/mobile_post_status_button.js | 93 | ||||
| -rw-r--r-- | src/components/mobile_post_status_button/mobile_post_status_button.vue | 55 |
2 files changed, 148 insertions, 0 deletions
diff --git a/src/components/mobile_post_status_button/mobile_post_status_button.js b/src/components/mobile_post_status_button/mobile_post_status_button.js new file mode 100644 index 00000000..3e77148a --- /dev/null +++ b/src/components/mobile_post_status_button/mobile_post_status_button.js @@ -0,0 +1,93 @@ +import { debounce } from 'lodash' + +const MobilePostStatusButton = { + data () { + return { + hidden: false, + scrollingDown: false, + inputActive: false, + oldScrollPos: 0, + amountScrolled: 0 + } + }, + created () { + if (this.autohideFloatingPostButton) { + this.activateFloatingPostButtonAutohide() + } + window.addEventListener('resize', this.handleOSK) + }, + destroyed () { + if (this.autohideFloatingPostButton) { + this.deactivateFloatingPostButtonAutohide() + } + window.removeEventListener('resize', this.handleOSK) + }, + computed: { + isLoggedIn () { + return !!this.$store.state.users.currentUser + }, + isHidden () { + return this.autohideFloatingPostButton && (this.hidden || this.inputActive) + }, + autohideFloatingPostButton () { + return !!this.$store.state.config.autohideFloatingPostButton + } + }, + watch: { + autohideFloatingPostButton: function (isEnabled) { + if (isEnabled) { + this.activateFloatingPostButtonAutohide() + } else { + this.deactivateFloatingPostButtonAutohide() + } + } + }, + methods: { + activateFloatingPostButtonAutohide () { + window.addEventListener('scroll', this.handleScrollStart) + window.addEventListener('scroll', this.handleScrollEnd) + }, + deactivateFloatingPostButtonAutohide () { + window.removeEventListener('scroll', this.handleScrollStart) + window.removeEventListener('scroll', this.handleScrollEnd) + }, + openPostForm () { + this.$store.dispatch('openPostStatusModal') + }, + handleOSK () { + // This is a big hack: we're guessing from changed window sizes if the + // on-screen keyboard is active or not. This is only really important + // for phones in portrait mode and it's more important to show the button + // in normal scenarios on all phones, than it is to hide it when the + // keyboard is active. + // Guesswork based on https://www.mydevice.io/#compare-devices + + // for example, iphone 4 and android phones from the same time period + const smallPhone = window.innerWidth < 350 + const smallPhoneKbOpen = smallPhone && window.innerHeight < 345 + + const biggerPhone = !smallPhone && window.innerWidth < 450 + const biggerPhoneKbOpen = biggerPhone && window.innerHeight < 560 + if (smallPhoneKbOpen || biggerPhoneKbOpen) { + this.inputActive = true + } else { + this.inputActive = false + } + }, + handleScrollStart: debounce(function () { + if (window.scrollY > this.oldScrollPos) { + this.hidden = true + } else { + this.hidden = false + } + this.oldScrollPos = window.scrollY + }, 100, { leading: true, trailing: false }), + + handleScrollEnd: debounce(function () { + this.hidden = false + this.oldScrollPos = window.scrollY + }, 100, { leading: false, trailing: true }) + } +} + +export default MobilePostStatusButton diff --git a/src/components/mobile_post_status_button/mobile_post_status_button.vue b/src/components/mobile_post_status_button/mobile_post_status_button.vue new file mode 100644 index 00000000..9cf45de3 --- /dev/null +++ b/src/components/mobile_post_status_button/mobile_post_status_button.vue @@ -0,0 +1,55 @@ +<template> + <div v-if="isLoggedIn"> + <button + class="new-status-button" + :class="{ 'hidden': isHidden }" + @click="openPostForm" + > + <i class="icon-edit" /> + </button> + </div> +</template> + +<script src="./mobile_post_status_button.js"></script> + +<style lang="scss"> +@import '../../_variables.scss'; + +.new-status-button { + width: 5em; + height: 5em; + border-radius: 100%; + position: fixed; + bottom: 1.5em; + right: 1.5em; + // TODO: this needs its own color, it has to stand out enough and link color + // is not very optimal for this particular use. + background-color: $fallback--fg; + background-color: var(--btn, $fallback--fg); + display: flex; + justify-content: center; + align-items: center; + box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3), 0px 4px 6px rgba(0, 0, 0, 0.3); + z-index: 10; + + transition: 0.35s transform; + transition-timing-function: cubic-bezier(0, 1, 0.5, 1); + + &.hidden { + transform: translateY(150%); + } + + i { + font-size: 1.5em; + color: $fallback--text; + color: var(--text, $fallback--text); + } +} + +@media all and (min-width: 801px) { + .new-status-button { + display: none; + } +} + +</style> |
