Last active
May 9, 2017 18:17
-
-
Save wokalski/d2543630ff2c2f4c98fb5b9e60130267 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
external view : ReactRe.reactClass = "SectionList" [@@bs.module "react-native"]; | |
module Common = { | |
type section 'a = {data: array 'a, key: option string}; | |
type renderBag 'a = { | |
item: 'a, | |
index: int, | |
section: section 'a, | |
separators: Js.t {. highlight : unit => unit, unhighlight : unit => unit} | |
}; | |
type separatorProps 'a = { | |
highlighted: bool, | |
leadingItem: option 'a, | |
leadingSection: option (section 'a), | |
section: section 'a, | |
trailingItem: option 'a, | |
trailingSection: option (section 'a) | |
}; | |
type viewToken 'a = | |
Js.t { | |
. | |
item : 'a, | |
key : string, | |
index : Js.undefined int, | |
isViewable : Js.boolean, | |
section : section 'a | |
}; | |
}; | |
module type Impl = {type item; let renderItem: Common.renderBag item => ReactRe.reactElement;}; | |
module CreateComponent (Impl: Impl) => { | |
include Common; | |
let createRenderBag ::item ::index ::section ::separators: Common.renderBag Impl.item => {item, index, section, separators}; | |
let createSeparatorProps | |
::highlighted | |
::leadingItem | |
::leadingSection | |
::section | |
::trailingItem | |
::trailingSection: Common.separatorProps Impl.item => { | |
highlighted, | |
leadingItem, | |
leadingSection, | |
section, | |
trailingItem, | |
trailingSection | |
}; | |
let renderItemFromJS renderItem jsItems => | |
renderItem ( | |
createRenderBag | |
item::jsItems##item | |
index::jsItems##index | |
section::jsItems##section | |
separators::jsItems##separators | |
); | |
let createElement: | |
sections::array (Common.section Impl.item) => | |
renderItem::(Common.renderBag Impl.item => ReactRe.reactElement) => | |
keyExtractor::(Impl.item => int => string) => | |
itemSeparatorComponent::(Common.separatorProps Impl.item => ReactRe.reactElement)? => | |
listEmptyComponent::(unit => ReactRe.reactElement)? => | |
listFooterComponent::ReactRe.reactElement? => | |
listHeaderComponent::ReactRe.reactElement? => | |
sectionSeparatorComponent::(Common.separatorProps Impl.item => ReactRe.reactElement)? => | |
extraData::'extraData? => | |
initialNumToRender::int? => | |
onEndReached::Js.t {. distanceFromEnd : float}? => | |
onEndReachedThreshold::float? => | |
onViewableItemsChanged:: | |
Js.t {. viewableItems : array (Common.viewToken Impl.item), changed : array (Common.viewToken Impl.item)}? => | |
onRefresh::(unit => unit)? => | |
refreshing::bool? => | |
renderSectionHeader::(Js.t {. section : Common.section Impl.item} => ReactRe.reactElement)? => | |
renderSectionFooter::(Js.t {. section : Common.section Impl.item} => ReactRe.reactElement)? => | |
stickySectionHeadersEnabled::bool? => | |
children::list ReactRe.reactElement => | |
ref::(ReactRe.reactRef => unit)? => | |
key::string? => | |
unit => | |
ReactRe.reactElement = | |
fun ::sections | |
::renderItem | |
::keyExtractor | |
::itemSeparatorComponent=? | |
::listEmptyComponent=? | |
::listFooterComponent=? | |
::listHeaderComponent=? | |
::sectionSeparatorComponent=? | |
::extraData=? | |
::initialNumToRender=? | |
::onEndReached=? | |
::onEndReachedThreshold=? | |
::onViewableItemsChanged=? | |
::onRefresh=? | |
::refreshing=? | |
::renderSectionHeader=? | |
::renderSectionFooter=? | |
::stickySectionHeadersEnabled=? => | |
ReactRe.wrapPropsShamelessly | |
view | |
Js.Undefined.( | |
{ | |
"sections": Array.map (fun {data, key} => {"data": data, "key": from_opt key}) sections, | |
"renderItem": renderItemFromJS renderItem, | |
"keyExtractor": keyExtractor, | |
"ItemSeparatorComponent": | |
from_opt ( | |
Utils.option_map | |
( | |
fun itemSeparatorComponent => { | |
let comp jsItems => | |
itemSeparatorComponent ( | |
createSeparatorProps | |
highlighted::(Js.to_bool jsItems##highlighted) | |
leadingItem::jsItems##leadingItem | |
leadingSection::jsItems##leadingSection | |
section::jsItems##section | |
trailingItem::jsItems##trailingItem | |
trailingSection::jsItems##trailingSection | |
); | |
comp | |
} | |
) | |
itemSeparatorComponent | |
), | |
"ListEmptyComponent": from_opt listEmptyComponent, | |
"ListFooterComponent": from_opt listFooterComponent, | |
"ListHeaderComponent": from_opt listHeaderComponent, | |
"SectionSeparatorComponent": from_opt sectionSeparatorComponent, | |
"extraData": from_opt extraData, | |
"initialNumToRender": from_opt initialNumToRender, | |
"onEndReached": from_opt onEndReached, | |
"onEndReachedThreshold": from_opt onEndReachedThreshold, | |
"onRefresh": from_opt onRefresh, | |
"onViewableItemsChanged": from_opt onViewableItemsChanged, | |
"refreshing": from_opt (Utils.optBoolToOptJsBoolean refreshing), | |
"renderSectionHeader": from_opt renderSectionHeader, | |
"renderSectionFooter": from_opt renderSectionFooter, | |
"stickySectionHeadersEnabled": | |
from_opt (Utils.optBoolToOptJsBoolean stickySectionHeadersEnabled) | |
} | |
); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment