Skip to content

Commit

Permalink
keep alive example
Browse files Browse the repository at this point in the history
  • Loading branch information
dupuchba committed Nov 24, 2023
1 parent 1a1fbcf commit 9704461
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clj/src/cljd/flutter.cljd
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@
(when-some [handle (.-handle state#)]
(.dispose handle)
(.-handle! state# nil)))
(~'-build [_# ^ResourceState state# ^widgets/BuildContext ctx#]
(~'-build [_# ^KeepAliveState state# ^widgets/BuildContext ctx#]
(if ~expr
(when-not (.-handle state#)
(-> (.-handle! state# (foundation/ChangeNotifier))
Expand Down
6 changes: 6 additions & 0 deletions samples/keep_alive/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{:paths ["src"] ; where your cljd files are
:deps {org.clojure/clojure {:mvn/version "1.10.1"}
tensegritics/clojuredart {:local/root "../../"}}
:aliases {:cljd {:main-opts ["-m" "cljd.build"]}}
:cljd/opts {:main sample.form
:kind :flutter}}
116 changes: 116 additions & 0 deletions samples/keep_alive/src/sample/keep_alive.cljd
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
(ns sample.form
"Faithful port of https://docs.flutter.dev/cookbook/forms/validation"
(:require ["package:flutter/material.dart" :as m]
[cljd.flutter :as f]
[cljd.string :as str]))

(defonce app-state (atom {}))

#_(defn main []
(f/run
m/MaterialApp
.home
m/Scaffold
.body
m/Center
;;(m/Container .height 400)
(m/Padding .padding (m/EdgeInsets.symmetric .horizontal 12))
;;(m/Container .color m/Colors.green.shade700)
;; enforce ratio 14+6spx / 5+4spy
(m/CustomPaint
.painter
(reify :extends m/CustomPainter
(paint [_ canvas size]
;; 1/ dessiner sur toute la largeur
(let [width (.-width size)
height (.-height size)
space-x-factor 0.3
circle-radius (/ width (+ 14 (* 6 space-x-factor)))
space-between-circles (* circle-radius (+ 1 space-x-factor))
paint (doto (m/Paint)
(.-color! m/Colors.red)
(.-style! m/PaintingStyle.fill))]
(loop [^int week 0]
(when (< week 5)
(loop [^int day 0]
(when (< day 7)
(let [x (+ (* (+ circle-radius space-between-circles) day) circle-radius)
y (+ (* (+ circle-radius space-between-circles) week) circle-radius)]
(.drawCircle canvas (m/Offset x y) circle-radius paint)
(recur (inc day)))))
(recur (inc week))))))
(shouldRepaint [_ _] false)))
(m/SizedBox .height 300 .width double/infinity)))

(defn main []
(f/run
m/MaterialApp
.home
m/Scaffold
.body
m/Center
;;(m/Container .height 400)
(m/Padding .padding (m/EdgeInsets.symmetric .horizontal 12))
:let [now (DateTime.now)]
;;(m/Container .color m/Colors.green.shade700)
;; enforce ratio 14+6spx / 5+4spy
(m/CustomPaint
.painter
(reify :extends m/CustomPainter
(paint [_ canvas size]
;; 1/ dessiner sur toute la largeur
(let [width (.-width size)
height (.-height size)
space-x-factor 0.3
circle-radius (/ width (+ 14 (* 6 space-x-factor)))
space-between-circles (* circle-radius (+ 1 space-x-factor))
paint (doto (m/Paint)
(.-color! m/Colors.red)
(.-style! m/PaintingStyle.fill))]
(loop [^int week 0]
(when (< week 5)
(loop [^int day 0]
(when (< day 7)
(let [x (+ (* (+ circle-radius space-between-circles) day) circle-radius)
y (+ (* (+ circle-radius space-between-circles) week) circle-radius)]
(when (and (== week 2) (== day 3))
(.drawRect canvas
(m/Rect.fromPoints
(m/Offset x (- y circle-radius))
(m/Offset
(+ (* (+ circle-radius space-between-circles) (+ 3 day)) circle-radius)
(+ y circle-radius)))
(doto paint
(.-color! (.withAlpha m/Colors.red 100))))
(doto paint
(.-color! m/Colors.red)))
(.drawCircle canvas (m/Offset x y) circle-radius paint)

(recur (inc day)))))
(recur (inc week))))))
(shouldRepaint [_ _] false)))
(m/SizedBox .height 300 .width double/infinity)))


(defn- date->first-day-for-month-and-first-day-next-month
[^DateTime month]
(let [{:flds [year month]} month
first-day (DateTime year month)
{y+1 .-year m+1 .-month} (.add first-day (Duration .days 32))
first-day-next-month (DateTime y+1 m+1)]
[first-day first-day-next-month]))

(defn main []
(f/run
m/MaterialApp
.home
m/Scaffold
.body
m/Center
:bind {:hey (atom nil)}
:color m/Colors.red
:padding {:top 40}
;;context ctx
;;:bind {:h 1}
:get [:hey]
(m/Text "hey")))

0 comments on commit 9704461

Please sign in to comment.