Skip to content

Commit

Permalink
update image primitive to use new style api (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
akinsho authored Jan 25, 2019
1 parent f5a539b commit a4e3184
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
21 changes: 10 additions & 11 deletions examples/Hello.re
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Logo = {

let make = () =>
component(slots => {
let (opacity, setOpacity, slots) = React.Hooks.state(1.0, slots);
let (logoOpacity, setOpacity, slots) = React.Hooks.state(1.0, slots);

let (rotation, slots) =
Hooks.animation(
Expand Down Expand Up @@ -42,16 +42,15 @@ module Logo = {
<View onMouseDown onMouseUp>
<Image
src="outrun-logo.png"
style={Style.make(
~width=512,
~height=256,
~opacity,
~transform=[
RotateY(Angle.from_radians(rotationY)),
RotateX(Angle.from_radians(rotation)),
],
(),
)}
style=Style.[
width(512),
height(256),
opacity(logoOpacity),
transform([
Transform.RotateY(Angle.from_radians(rotationY)),
Transform.RotateX(Angle.from_radians(rotation)),
]),
]
/>
</View>;
});
Expand Down
19 changes: 9 additions & 10 deletions examples/Slider.re
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,15 @@ module AdjustableLogo = {
<View>
<Image
src="outrun-logo.png"
style={Style.make(
~width=512,
~height=256,
~transform=[
RotateZ(Angle.from_radians(rotationZ)),
RotateY(Angle.from_radians(rotationY)),
RotateX(Angle.from_radians(rotationX)),
],
(),
)}
style=Style.[
width(512),
height(256),
transform([
Transform.RotateZ(Angle.from_radians(rotationZ)),
Transform.RotateY(Angle.from_radians(rotationY)),
Transform.RotateX(Angle.from_radians(rotationX)),
]),
]
/>
</View>
<View style=controlsStyle>
Expand Down
10 changes: 6 additions & 4 deletions src/UI/Primitives.re
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,14 @@ module Image = {
~onMouseUp=?,
~onMouseWheel=?,
~ref=?,
~style=Style.defaultStyle,
~style=Style.emptyImageStyle,
~src="",
children,
) =>
component((_: UiReact.Hooks.empty) =>
{
make: () => {
let styles = Style.create(~style, ());
let events =
NodeEvents.make(
~ref?,
Expand All @@ -207,10 +208,11 @@ module Image = {
);
let node = (new ImageNode.imageNode)(src);
node#setEvents(events);
node#setStyle(style);
node#setStyle(styles);
Obj.magic(node);
},
configureInstance: (~isFirstRender as _, node) => {
let styles = Style.create(~style, ());
let events =
NodeEvents.make(
~ref?,
Expand All @@ -221,7 +223,7 @@ module Image = {
(),
);
node#setEvents(events);
node#setStyle(style);
node#setStyle(styles);
node;
},
children,
Expand All @@ -235,7 +237,7 @@ module Image = {
~onMouseUp=?,
~onMouseWheel=?,
~ref=?,
~style=Style.defaultStyle,
~style=Style.emptyImageStyle,
~src="",
~children,
(),
Expand Down
2 changes: 2 additions & 0 deletions src/UI/Style.re
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,11 @@ type fontProps = [ | `FontFamily(string) | `FontSize(int)];
*/
type textStyleProps = [ fontProps | props];
type viewStyleProps = [ props];
type imageStyleProps = [ props];

let emptyTextStyle: list(textStyleProps) = [];
let emptyViewStyle: list(viewStyleProps) = [];
let emptyImageStyle: list(imageStyleProps) = [];

let flexDirection = d => {
let dir =
Expand Down

0 comments on commit a4e3184

Please sign in to comment.