1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
use polyhorn_android_sys::Rect;
use polyhorn_core::CommandBuffer;
use polyhorn_ui::geometry::Size;
use polyhorn_ui::layout::LayoutGuide;
use std::pin::Pin;
use std::task::{Context, Poll};

use crate::prelude::*;
use crate::raw::{Builtin, Container, Convert, Environment, OpaqueContainer, Platform};
use crate::{Component, Key};

pub struct AnimationHandle;

impl std::future::Future for AnimationHandle {
    type Output = ();

    fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
        todo!()
    }
}

impl polyhorn_ui::animation::AnimationHandle for AnimationHandle {}

pub struct Animator;

impl polyhorn_ui::animation::Animator for Animator {
    type AnimationHandle = AnimationHandle;

    fn start(&mut self, _animation: polyhorn_ui::animation::Animation) -> Self::AnimationHandle {
        todo!()
    }
}

pub struct ViewHandle;

impl polyhorn_ui::animation::Animatable for ViewHandle {
    type Animator = Animator;
    type CommandBuffer = ();

    fn animate<F>(&mut self, _animations: F)
    where
        F: FnOnce(&mut Self::Animator) + Send + 'static,
    {
        todo!()
    }

    fn animate_with_buffer<F>(&mut self, _buffer: &mut Self::CommandBuffer, _animations: F)
    where
        F: FnOnce(&mut Self::Animator) + Send + 'static,
    {
        todo!()
    }
}

impl polyhorn_ui::handles::ViewHandle for ViewHandle {
    fn layout_guide(&self) -> LayoutGuide<f32> {
        todo!()
    }

    fn size<F>(&self, _callback: F)
    where
        F: FnOnce(Size<f32>) + Send + 'static,
    {
        todo!()
    }

    fn size_with_buffer<F>(&self, _buffer: &mut Self::CommandBuffer, _callback: F)
    where
        F: FnOnce(Size<f32>) + Send + 'static,
    {
        todo!()
    }
}

impl Container for polyhorn_android_sys::View {
    fn mount(&mut self, child: &mut OpaqueContainer, environment: &mut Environment) {
        if let Some(view) = child.container().to_view() {
            self.add_view(environment.env(), &view)
        }
    }

    fn unmount(&mut self) {}

    fn to_view(&self) -> Option<polyhorn_android_sys::View> {
        Some(self.clone())
    }
}

pub type View = polyhorn_ui::components::View<Platform, ViewHandle>;

impl Component for View {
    fn render(&self, manager: &mut Manager) -> Element {
        let reference = use_reference!(manager, None);

        let style = self.style;

        use_layout_effect!(manager, move |link, buffer| {
            if let Some(view) = reference.apply(link, |&mut id| id) {
                buffer.mutate(&[view], move |views, environment| {
                    let layout = views[0].layout().unwrap().current();

                    if let Some(view) = views[0].downcast_mut::<polyhorn_android_sys::View>() {
                        view.set_background_color(
                            environment.env(),
                            style.background_color.convert(environment.env()),
                        );
                        view.set_frame(
                            environment.env(),
                            Rect::new(
                                environment.env(),
                                layout.origin.x,
                                layout.origin.y,
                                layout.size.width,
                                layout.size.height,
                            ),
                        );
                    }
                });
            }
        });

        Element::builtin(
            Key::new(()),
            Builtin::View(self.style),
            manager.children(),
            Some(reference.weak(manager)),
        )
    }
}