Skip to content

Commit

Permalink
Merge pull request #25 from azimgd/example-nav
Browse files Browse the repository at this point in the history
Enhanced example app
  • Loading branch information
azimgd authored Feb 23, 2025
2 parents dbfa726 + 8f8d8a3 commit 8ef903f
Show file tree
Hide file tree
Showing 15 changed files with 1,242 additions and 206 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package shadowlist.example
import android.os.Bundle;

import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
import com.facebook.react.defaults.DefaultReactActivityDelegate

class MainActivity : ReactActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(null)
}

/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
Expand Down
144 changes: 144 additions & 0 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,93 @@ PODS:
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- react-native-menu (1.2.2):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- react-native-safe-area-context (5.2.0):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- react-native-safe-area-context/common (= 5.2.0)
- react-native-safe-area-context/fabric (= 5.2.0)
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- react-native-safe-area-context/common (5.2.0):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- react-native-safe-area-context/fabric (5.2.0):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- react-native-safe-area-context/common
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- React-nativeconfig (0.76.5)
- React-NativeModulesApple (0.76.5):
- glog
Expand Down Expand Up @@ -1509,6 +1596,51 @@ PODS:
- React-logger (= 0.76.5)
- React-perflogger (= 0.76.5)
- React-utils (= 0.76.5)
- RNScreens (4.9.0):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-RCTImage
- React-rendererdebug
- React-utils
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- RNScreens/common (= 4.9.0)
- Yoga
- RNScreens/common (4.9.0):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-RCTImage
- React-rendererdebug
- React-utils
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- shadowlist (0.4.24):
- DoubleConversion
- glog
Expand Down Expand Up @@ -1571,6 +1703,8 @@ DEPENDENCIES:
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
- React-Mapbuffer (from `../node_modules/react-native/ReactCommon`)
- React-microtasksnativemodule (from `../node_modules/react-native/ReactCommon/react/nativemodule/microtasks`)
- "react-native-menu (from `../node_modules/@react-native-menu/menu`)"
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
- React-nativeconfig (from `../node_modules/react-native/ReactCommon`)
- React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`)
- React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`)
Expand Down Expand Up @@ -1598,6 +1732,7 @@ DEPENDENCIES:
- React-utils (from `../node_modules/react-native/ReactCommon/react/utils`)
- ReactCodegen (from `build/generated/ios`)
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- RNScreens (from `../node_modules/react-native-screens`)
- shadowlist (from `../..`)
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)

Expand Down Expand Up @@ -1677,6 +1812,10 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon"
React-microtasksnativemodule:
:path: "../node_modules/react-native/ReactCommon/react/nativemodule/microtasks"
react-native-menu:
:path: "../node_modules/@react-native-menu/menu"
react-native-safe-area-context:
:path: "../node_modules/react-native-safe-area-context"
React-nativeconfig:
:path: "../node_modules/react-native/ReactCommon"
React-NativeModulesApple:
Expand Down Expand Up @@ -1731,6 +1870,8 @@ EXTERNAL SOURCES:
:path: build/generated/ios
ReactCommon:
:path: "../node_modules/react-native/ReactCommon"
RNScreens:
:path: "../node_modules/react-native-screens"
shadowlist:
:path: "../.."
Yoga:
Expand Down Expand Up @@ -1772,6 +1913,8 @@ SPEC CHECKSUMS:
React-logger: 697873f06b8ba436e3cddf28018ab4741e8071b6
React-Mapbuffer: c174e11bdea12dce07df8669d6c0dc97eb0c7706
React-microtasksnativemodule: 8a80099ad7391f4e13a48b12796d96680f120dc6
react-native-menu: bd7ae6c2e88ec505a4e0e098f0683b27195b2d12
react-native-safe-area-context: a95e75ab816db4438a319aa4b43dfe6def22026f
React-nativeconfig: f7ab6c152e780b99a8c17448f2d99cf5f69a2311
React-NativeModulesApple: 70600f7edfc2c2a01e39ab13a20fd59f4c60df0b
React-perflogger: ceb97dd4e5ca6ff20eebb5a6f9e00312dcdea872
Expand Down Expand Up @@ -1799,6 +1942,7 @@ SPEC CHECKSUMS:
React-utils: 541c6cca08f32597d4183f00e83eef2ed20d4c54
ReactCodegen: daa13d9e48c9bdb1daac4bd694b9dd54e06681df
ReactCommon: a6b87a7591591f7a52d9c0fec3aa05e0620d5dd3
RNScreens: 3536657dc38c66208d2e6e05c37021a3ab13f93c
shadowlist: b7285529cca7db43435a80ac41188e593cc0be45
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Yoga: fcc198acd4a55599b3468cfb6ebc526baff5f06e
Expand Down
7 changes: 6 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
},
"dependencies": {
"@faker-js/faker": "^9.3.0",
"@react-native-menu/menu": "^1.2.2",
"@react-navigation/native": "^7.0.14",
"@react-navigation/native-stack": "^7.2.0",
"react": "18.3.1",
"react-native": "0.76.5"
"react-native": "0.76.5",
"react-native-safe-area-context": "^5.2.0",
"react-native-screens": "^4.9.0"
},
"devDependencies": {
"@babel/core": "^7.25.2",
Expand Down
145 changes: 10 additions & 135 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,140 +1,15 @@
import { useRef, useCallback, useEffect } from 'react';
import { View, StyleSheet, Text } from 'react-native';
import type { DirectEventHandler } from 'react-native/Libraries/Types/CodegenTypes';
import {
Shadowlist,
type OnStartReached,
type OnEndReached,
type OnVisibleChange,
type OnScroll,
type SLContainerRef,
} from 'shadowlist';
import useData from './useData';
import Element from './Element';
import { createStaticNavigation, DarkTheme } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import HomeScreen from './HomeScreen';

const ITEMS_COUNT = 50;
const IS_INVERTED = false;
const IS_HORIZONTAL = false;
const INITIAL_SCROLL_INDEX = 0;
const FINAL_SCROLL_INDEX = 0;

const ListHeaderComponent = () => (
<View style={styles.static}>
<Text style={styles.text}>Header</Text>
</View>
);

const ListFooterComponent = () => (
<View style={styles.static}>
<Text style={styles.text}>Footer</Text>
</View>
);
const RootStack = createNativeStackNavigator({
screens: {
Home: HomeScreen,
},
});

const ListEmptyComponent = () => (
<View style={styles.static}>
<Text style={styles.text}>Empty</Text>
</View>
);
const Navigation = createStaticNavigation(RootStack);

export default function App() {
const data = useData({ length: ITEMS_COUNT, inverted: IS_INVERTED });
const ref = useRef<SLContainerRef>(null);

useEffect(() => {
if (!FINAL_SCROLL_INDEX) return;
setTimeout(() => {
ref.current?.scrollToIndex({ index: FINAL_SCROLL_INDEX });
}, 1000);
}, []);

const onStartReached = useCallback<DirectEventHandler<OnStartReached>>(
(event) => {
!IS_INVERTED ? data.loadPrepend() : data.loadAppend();
event.nativeEvent.distanceFromStart;
},
[data]
);

const onEndReached = useCallback<DirectEventHandler<OnEndReached>>(
(event) => {
!IS_INVERTED ? data.loadAppend() : data.loadPrepend();
event.nativeEvent.distanceFromEnd;
},
[data]
);

const onVisibleChange = useCallback<DirectEventHandler<OnVisibleChange>>(
(event) => {
event.nativeEvent.visibleEndIndex;
},
[]
);

const onScroll = useCallback<DirectEventHandler<OnScroll>>((event) => {
event.nativeEvent.contentOffset.y;
}, []);

const templateYarrow = () => (
<Element
onPress={(index: number) => data.update(index)}
data={data.data}
style={{ backgroundColor: '#00cec9' }}
/>
);

const templateRobin = () => (
<Element
onPress={(index: number) => data.update(index)}
data={data.data}
style={{ backgroundColor: '#fdcb6e' }}
/>
);

return (
<View style={styles.container}>
<Shadowlist
ref={ref}
templates={{
ListTemplateComponentUniqueIdYarrow: templateYarrow,
ListTemplateComponentUniqueIdRobin: templateRobin,
}}
data={data.data}
onVisibleChange={onVisibleChange}
onStartReached={onStartReached}
onEndReached={onEndReached}
onScroll={onScroll}
ListHeaderComponent={ListHeaderComponent}
ListHeaderComponentStyle={styles.static}
ListFooterComponent={ListFooterComponent}
ListFooterComponentStyle={styles.static}
ListEmptyComponent={ListEmptyComponent}
ListEmptyComponentStyle={styles.static}
inverted={IS_INVERTED}
horizontal={IS_HORIZONTAL}
initialScrollIndex={INITIAL_SCROLL_INDEX}
numColumns={1}
contentContainerStyle={styles.list}
/>
</View>
);
return <Navigation theme={DarkTheme} />;
}

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#333333',
paddingTop: 60,
},
list: {
flex: 1,
},
text: {
color: '#333333',
backgroundColor: '#1dd1a1',
padding: 16,
},
static: {
height: 120,
backgroundColor: '#576574',
},
});
Loading

0 comments on commit 8ef903f

Please sign in to comment.