@@ -24,16 +24,21 @@ class AgendaList extends Component {
2424 ...SectionList . propTypes ,
2525 /** day format in section title. Formatting values: http://arshaw.com/xdate/#Formatting */
2626 dayFormat : PropTypes . string ,
27+ /** a function to custom format the section header's title */
28+ dayFormatter : PropTypes . func ,
2729 /** whether to use moment.js for date string formatting
2830 * (remember to pass 'dayFormat' with appropriate format, like 'dddd, MMM D') */
2931 useMoment : PropTypes . bool ,
32+ /** whether to mark today's title with the "Today, ..." string. Default = true */
33+ markToday : PropTypes . bool ,
3034 /** style passed to the section view */
3135 sectionStyle : PropTypes . oneOfType ( [ PropTypes . object , PropTypes . number , PropTypes . array ] )
3236 }
3337
3438 static defaultProps = {
3539 dayFormat : 'dddd, MMM d' ,
36- stickySectionHeadersEnabled : true
40+ stickySectionHeadersEnabled : true ,
41+ markToday : true
3742 }
3843
3944 constructor ( props ) {
@@ -134,35 +139,44 @@ class AgendaList extends Component {
134139 }
135140
136141 renderSectionHeader = ( { section : { title} } ) => {
137- if ( this . props . renderSectionHeader ) {
138- return this . props . renderSectionHeader ( ) ;
142+ const { renderSectionHeader, dayFormatter, dayFormat, useMoment, markToday, sectionStyle} = this . props ;
143+
144+ if ( renderSectionHeader ) {
145+ return renderSectionHeader ( title ) ;
139146 }
140147
141148 let sectionTitle = title ;
142149
143- if ( this . props . dayFormat ) {
144- let date ;
145- let today ;
146-
147- if ( this . props . useMoment ) {
148- date = moment ( title ) . format ( this . props . dayFormat ) ;
149- today = moment ( ) . format ( this . props . dayFormat ) ;
150+ if ( dayFormatter ) {
151+ sectionTitle = dayFormatter ( title ) ;
152+ } else if ( dayFormat ) {
153+ if ( useMoment ) {
154+ sectionTitle = moment ( title ) . format ( dayFormat ) ;
150155 } else {
151- date = XDate ( title ) . toString ( this . props . dayFormat ) ;
152- today = XDate ( ) . toString ( this . props . dayFormat ) ;
156+ sectionTitle = XDate ( title ) . toString ( dayFormat ) ;
153157 }
158+ }
154159
160+ if ( markToday ) {
155161 const todayString = XDate . locales [ XDate . defaultLocale ] . today || commons . todayString ;
156- sectionTitle = date === today ? `${ todayString } , ${ date } ` : date ;
162+ const today = XDate ( ) . toString ( "yyyy-MM-d" ) ;
163+ sectionTitle = title === today ? `${ todayString } , ${ sectionTitle } ` : sectionTitle ;
157164 }
158165
159166 return (
160- < Text allowFontScaling = { false } style = { [ this . style . sectionText , this . props . sectionStyle ] } onLayout = { this . onHeaderLayout } > { sectionTitle } </ Text >
167+ < Text
168+ allowFontScaling = { false }
169+ style = { [ this . style . sectionText , sectionStyle ] }
170+ onLayout = { this . onHeaderLayout }
171+ >
172+ { sectionTitle }
173+ </ Text >
161174 ) ;
162175 }
163176
164177 keyExtractor = ( item , index ) => {
165- return _ . isFunction ( this . props . keyExtractor ) ? this . props . keyExtractor ( item , index ) : String ( index ) ;
178+ const { keyExtractor} = this . props ;
179+ return _ . isFunction ( keyExtractor ) ? keyExtractor ( item , index ) : String ( index ) ;
166180 }
167181
168182 render ( ) {
0 commit comments