Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Fix keyed reconciliation #712

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/Examples.re
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ let state: state = {
render: _ => NestedClickable.render(),
source: "NestedClickable.re",
},
{
name: "Keyed List",
render: _ => KeyedListExample.render(),
source: "KeyedListExample.re",
},
],
selectedExample: "Animation",
};
Expand Down
69 changes: 69 additions & 0 deletions examples/KeyedListExample.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
open Revery;
open Revery.UI;
open Revery.UI.Components;

module Styles = {
open Style;

let container = [];

let toggle = [
flexDirection(`Row),
justifyContent(`Center),
alignItems(`Center),
];

let item = (~borderOpacity) => [
border(~width=2, ~color=Color.rgba(0., 1., 1., borderOpacity)),
];

let list = [];

let text = [
marginBottom(10),
fontFamily("Roboto-Regular.ttf"),
fontSize(16),
];
};

let toggle = (~checked, ~onChange, ()) =>
<View style=Styles.toggle>
<Checkbox checked onChange />
<Text text="Toggle Item 3" style=Styles.text />
</View>;

let%component item = (~label, ()) => {
let%hook (borderOpacity, _, _) =
Hooks.animation(Animation.(animate(Time.ms(500)) |> tween(1., 0.)));

<View style={Styles.item(~borderOpacity)}>
<Text text=label style=Styles.text />
</View>;
};

let list = (~children, ()) => <View style=Styles.list> children </View>;

let items = [
(React.Key.create(), "Item 1"),
(React.Key.create(), "Item 2"),
(React.Key.create(), "Item 3"),
(React.Key.create(), "Item 4"),
];

let%component container = () => {
let%hook (checked, setChecked) = Hooks.state(false);

let items =
checked ? items : List.filter(((_, label)) => label != "Item 3", items);

<View style=Styles.container>
<toggle checked onChange={() => setChecked(checked => !checked)} />
<list>
{items
|> List.map(((_, label)) => <item key label />)
|> React.listToElement}
</list>
</View>;
};

let render = () => <container />;