Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Request for guidance for custom element #50

Open
p14n opened this issue May 23, 2015 · 4 comments
Open

Request for guidance for custom element #50

p14n opened this issue May 23, 2015 · 4 comments

Comments

@p14n
Copy link

p14n commented May 23, 2015

Hi there,

I'm looking to create a custom drawing as part of a component. In the Android API it seems I'd subclass view and implement onDraw to draw directly on the canvas. I'm not sure in neko if it's possible to do this without writing my custom component in Java - it seems custom elements need a classname.

Any pointer much appreciated,
Cheers,
Dean

@p14n p14n changed the title Request for guidance Request for guidance for custom element May 23, 2015
@p14n
Copy link
Author

p14n commented May 23, 2015

I think I found the answer - a :custom-constructor for a View.

@alexander-yakushev
Copy link

Indeed, I used :custom-constructor attribute to create a proxy where I override onDraw. So did it work for you?

@p14n
Copy link
Author

p14n commented May 25, 2015

Yes it did - thanks

(defn draw-circle [^Canvas canvas]
  (let [paint (Paint. Paint/ANTI_ALIAS_FLAG)]
    (.drawCircle canvas 0 0 20 paint)))

(defn main-layout [activity] [:linear-layout {:orientation :horizontal}
                      [:edit-text {:hint "Event name"}]
                      (make-ui activity [:view {:custom-constructor
                       (fn [ctx]
                         (proxy [android.view.View] [ctx]
                           (onDraw [^Canvas canvas]
                             (draw-circle canvas)
                             )))}])])

@alexander-yakushev
Copy link

OK, so I see you called make-ui yourself. It's fine to do that, but you won't be able to find that custom-view by ID if you later add :id attribute to it. So in fact you could just do:

(defn main-layout [activity]
  [:linear-layout {:orientation :horizontal}
   [:edit-text {:hint "Event name"}]
   [:view {:custom-constructor
           (fn [ctx]
             (proxy [android.view.View] [ctx]
               (onDraw [^Canvas canvas]
                 (draw-circle canvas)
                 )))}]])

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants