Skip to content

Commit

Permalink
add basic implementation .
Browse files Browse the repository at this point in the history
  • Loading branch information
xyhp915 committed Oct 31, 2020
1 parent 7824973 commit d8bfa1d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
6 changes: 6 additions & 0 deletions resources/static/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 11 additions & 10 deletions src/main/frontend/components/editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down
1 change: 1 addition & 0 deletions src/main/frontend/page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
29 changes: 29 additions & 0 deletions src/main/frontend/ui.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions src/main/frontend/util.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit d8bfa1d

Please sign in to comment.