Skip to content

Instantly share code, notes, and snippets.

@desmond-dsouza
Created January 22, 2018 16:57
Show Gist options
  • Save desmond-dsouza/36d5b041943d0aa57554e8e684a1dbe3 to your computer and use it in GitHub Desktop.
Save desmond-dsouza/36d5b041943d0aa57554e8e684a1dbe3 to your computer and use it in GitHub Desktop.
Where to put the "Section A" and "Section B" headers? How to get them back out in renderSectionHeader? (see code comments)
open BsReactNative;
type item = {
name: string,
age: int
};
let data = [|
{name: "Devin", age: 22},
{name: "Jackson", age: 12},
{name: "James", age: 14},
{name: "Joel", age: 42},
{name: "John", age: 30},
{name: "Jillian", age: 51},
{name: "Jimmy", age: 31},
{name: "Julie", age: 23},
{name: "Amy", age: 27},
{name: "Andrew", age: 24}
|];
let sec = SectionList.section;
let sections =
SectionList.(
sections([|
/* WHERE TO PUT "Section A" and "Section B" header info? I'm trying ~key, which is probably wrong */
sec(~data=[|data[0], data[1], data[4]|], ~key="Section A", ()),
sec(~data, ~key="Section B", ()),
sec(~data=[|data[9], data[8], data[7], data[6]|], ~key="Section C", ())
|])
);
let component = ReasonReact.statelessComponent("Lister");
let flatSty =
Style.(
style([fontSize(Float(62.)), backgroundColor("skyblue"), margin(Pt(10.))])
);
let hdrSty =
Style.(style([borderBottomColor("black"), borderBottomWidth(5.)]));
let f = Style.textAlign;
let make = _children => {
...component,
render: _self =>
<ScrollView>
<FlatList
data
keyExtractor=((x, _i) => x.name)
renderItem=(
FlatList.renderItem(x => <Text style=flatSty value=x.item.name />)
)
/>
<SectionList
sections
renderItem=(
SectionList.renderItem(x => <Touch.Box name=x.item.name />)
)
keyExtractor=((x, _i) => x.name)
renderSectionHeader=(
(s: {. "section": SectionList.section(item)}) =>
<View style=hdrSty>
<Text
style=Style.(style([fontSize(Float(40.))]))
value=(
/* How to extract back out "Section A" "Section B" header info? */
switch (SectionList.((s##section).key)) {
| Some(x) => x
| None => "--"
}
)
/>
</View>
)
/>
</ScrollView>
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment