add basic implementation .

pull/645/head
charlie 2020-11-01 00:20:10 +08:00
parent 7824973abc
commit d8bfa1dad5
5 changed files with 51 additions and 10 deletions

View File

@ -89,6 +89,12 @@ html {
font-family: var(--ls-font-family), Inter, sans-serif, system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI", Roboto, "Helvetica Neue", Arial ,"Noto Sans", serif, Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol!important;
}
html.is-ios, html.is-ios > body {
-webkit-overflow-scrolling : touch;
overflow: auto !important;
height: 100% !important;
}
@supports (font-variation-settings: normal) {
html {
font-family: 'Inter var', sans-serif;

View File

@ -217,16 +217,17 @@
(rum/defc mobile-bar < rum/reactive
[parent-state parent-id]
[:div.bg-base-2 {:style {:position "fixed"
:bottom 0
:width "100%"
:left 0
:justify-content "center"
:height "2.5rem"
:display "flex"
:align-items "center"
;; This element should be the upper-most in most situations
:z-index 99999999}}
[:div.bg-base-2.fix-ios-fixed-bottom
{:style {:position "fixed"
:bottom 0
:width "100%"
:left 0
:justify-content "center"
:height "2.5rem"
:display "flex"
:align-items "center"
;; This element should be the upper-most in most situations
:z-index 99999999}}
[:button.bottom-action
{:style {:padding "5px"}
:on-click #(editor-handler/adjust-block-level! parent-state :right)}

View File

@ -12,6 +12,7 @@
(rum/defc current-page < rum/reactive
{:did-mount (fn [state]
(state/set-root-component! (:rum/react-component state))
(ui/setup-patch-ios-fixed-bottom-position)
state)}
[]
(when-let [route-match (state/sub :route-match)]

View File

@ -193,6 +193,35 @@
(defn get-scroll-top []
(.-scrollTop (main-node)))
(defn setup-patch-ios-fixed-bottom-position
"fix a common issue about ios webpage viewport
when soft keyboard setup"
[]
(if (and
(util/ios?)
(not (nil? js/window.visualViewport)))
(let [viewport js/visualViewport
style (js/document.createElement "style")]
(.add (.-classList js/document.documentElement) "is-ios")
(set! (.-id style) "dynamic-style-scope")
(.appendChild js/document.head style)
(let [sheet (.-sheet style)
type "resize"
handler
(fn []
(let [vh (.-height viewport)
rule (.. sheet -rules (item 0))
set-top #(set! (.. rule -style -top) (str % "px"))]
(set-top vh)
(prn "resize " vh (.. rule -style -top))))]
(.insertRule sheet ".fix-ios-fixed-bottom {bottom:unset !important; transform: translateY(-100%); top: 0px;}")
(.addEventListener viewport type handler false)
(handler)
(fn []
(.removeEventListener viewport type handler)
(prn "teardown viewport " type)))
)))
;; FIXME: compute the right scroll position when scrolling back to the top
(defn on-scroll
[on-load on-top-reached]

View File

@ -18,6 +18,10 @@
[clojure.pprint :refer [pprint]]
[goog.userAgent]))
;; envs
(defn ios? []
(not (nil? (re-find #"iPad|iPhone|iPod" (.-userAgent js/navigator)))))
(defn format
[fmt & args]
(apply gstring/format fmt args))