diff --git a/example/src/components/LogListDisplay.tsx b/example/src/components/LogListDisplay.tsx new file mode 100644 index 00000000..67a32f09 --- /dev/null +++ b/example/src/components/LogListDisplay.tsx @@ -0,0 +1,146 @@ + +import * as React from 'react'; +import { StyleSheet, View, Text, ScrollView, type ViewProps, type TextStyle } from 'react-native'; + +import { Helpers } from 'react-native-ios-utilities'; + + +export type LogListDisplayItem = { + timestamp: string; + itemTitle: string; + index: number; +}; + +export type LogListDisplayRef = { + addItem: (itemTitle: string) => void; +}; + +export type LogListDisplayProps = ViewProps & { + maxItemsToShow?: number; + logItemIndexTextStyle?: TextStyle; + logItemTimestampTextStyle?: TextStyle; + logItemTitleTextStyle?: TextStyle; +}; + +export const LogListDisplay = React.forwardRef< + LogListDisplayRef, + LogListDisplayProps +>((props, ref) => { + const [events, setEvents] = React.useState>([]); + + const hasEvents = (events.length > 0); + const maxItemsToShow = props.maxItemsToShow ?? 15; + const recentEvents = events.reverse().slice(-maxItemsToShow); + + React.useImperativeHandle(ref, () => ({ + addItem: (itemTitle) => { + const date = new Date(); + + const h = Helpers.pad(date.getHours ()); + const m = Helpers.pad(date.getMinutes()); + const s = Helpers.pad(date.getSeconds()); + + const ms = Helpers.pad(date.getMilliseconds(), 3); + + setEvents((prevValue) => ([ ...prevValue, { + timestamp: `${h}:${m}:${s}.${ms}`, + itemTitle: itemTitle, + index: prevValue.length + }])); + }, + })); + + return ( + + {hasEvents? ( + + {recentEvents.map((item) => ( + + + {`${Helpers.pad(item.index, 3)}`} + + + {`${item.timestamp}`} + + + {item.itemTitle} + + + ))} + + ):( + + {'No Events To Show'} + + )} + + ); +}); + +const styles = StyleSheet.create({ + eventContainer: { + marginTop: 15, + height: 150, + backgroundColor: 'rgba(255,255,255,0.3)', + borderRadius: 10, + paddingHorizontal: 12, + paddingVertical: 7, + }, + eventContainerEmpty: { + alignItems: 'center', + justifyContent: 'center', + }, + eventEmptyText: { + fontWeight: '600', + fontSize: 16, + color: 'rgba(0,0,0,0.4)', + }, + eventListItemContainer: { + flexDirection: 'row', + }, + logItemText: { + fontSize: 12, + fontVariant: ['tabular-nums'], + }, + logItemIndexText: { + minWidth: 30, + fontWeight: '600', + color: 'rgba(0,0,0,0.3)', + }, + logItemTimestampText: { + minWidth: 80, + fontWeight: '300', + color: 'rgba(0,0,0,0.75)', + }, + logItemTitleText: { + fontWeight: '400', + color: 'rgba(0,0,0,0.9)', + }, +}); \ No newline at end of file