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; 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) { @supports (font-variation-settings: normal) {
html { html {
font-family: 'Inter var', sans-serif; font-family: 'Inter var', sans-serif;

View File

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

View File

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

View File

@ -193,6 +193,35 @@
(defn get-scroll-top [] (defn get-scroll-top []
(.-scrollTop (main-node))) (.-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 ;; FIXME: compute the right scroll position when scrolling back to the top
(defn on-scroll (defn on-scroll
[on-load on-top-reached] [on-load on-top-reached]

View File

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