Skip to content

Commit

Permalink
Merge pull request #1286 from sergiirocks/feat/transitionstate
Browse files Browse the repository at this point in the history
Add Value property to TransitionState
  • Loading branch information
kusma authored Aug 20, 2019
2 parents f4b700b + 6d4909c commit c84fe1a
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

### Fuse.Triggers.Actions.TransitionState
- Added `Value` property on `TransitionState`.

# 1.12

Expand Down
44 changes: 39 additions & 5 deletions Source/Fuse.Triggers/Actions/StateTransition.uno
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,64 @@ namespace Fuse.Triggers.Actions
Next,
}


/**
@mount Trigger Actions
An action that controls state of a @StateGroup.
## Example
The following example displays a red panel that will turn its color in green when clicked.
<Panel ux:Name="thePanel" Width="100" Height="100">
<StateGroup ux:Name="stateGroup">
<State ux:Name="redState">
<Change thePanel.Color="#f00" Duration="0.2"/>
</State>
<State ux:Name="greenState">
<Change thePanel.Color="#0f0" Duration="0.2"/>
</State>
</StateGroup>
<Clicked>
<TransitionState Value="greenState" Target="stateGroup" />
</Clicked>
</Panel>
*/
public class TransitionState : TriggerAction
{
/** StateGroup to be be transitioned **/
public StateGroup Target { get; set; }

public TransitionStateType Type { get; set; }


/** Explicit target state to transition to **/
public State Value { get; set; }

protected override void Perform(Node target)
{
var t = Target;
var s = Value;

if (t == null)
{
Fuse.Diagnostics.UserError( "Missing `Target`", this );
return;
}


if (s != null) {
t.Goto(s);
return;
}

switch (Type)
{
case TransitionStateType.Next:
t.GotoNextState();
break;
return;
}

Fuse.Diagnostics.UserWarning( "Provide `Value` or `Type`", this );
}
}
}
}
14 changes: 14 additions & 0 deletions Source/Fuse.Triggers/Tests/StateGroup.Test.uno
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,19 @@ namespace Fuse.Triggers.Test
Assert.AreEqual(p.s2,p.sg.Active);
}
}

[Test]
public void TransitionStateValue()
{
var p = new UX.StateGroup.TransitionStateValue();
using (var root = TestRootPanel.CreateWithChild(p))
{
Assert.AreEqual(p.s1,p.sg.Active);

p.t1.Pulse();
root.PumpDeferred();
Assert.AreEqual(p.s3,p.sg.Active);
}
}
}
}
11 changes: 11 additions & 0 deletions Source/Fuse.Triggers/Tests/UX/StateGroup.TransitionStateValue.ux
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Panel ux:Class="UX.StateGroup.TransitionStateValue">
<StateGroup ux:Name="sg">
<State ux:Name="s1"/>
<State ux:Name="s2"/>
<State ux:Name="s3"/>
</StateGroup>

<Timeline ux:Name="t1">
<TransitionState Target="sg" Value="s3"/>
</Timeline>
</Panel>

0 comments on commit c84fe1a

Please sign in to comment.