// TODO: ^^ this reason why it was commented by Umed is because we need to update "edited" messages as well (this requires query to the host)
// if (localMessages.length) {
onMessagesLoad("local", localMessageBundles)
// } else {
const remoteMessageBundles = await AppController.message.getFromHost({
localMessageBundles: localMessageBundles,
roomId: room.id,
directionDate: null,
searchId: null,
direction: "all",
})
onMessagesLoad("remote", remoteMessageBundles)
// }
}
function onMessagesLoad(
source: "local" | "remote",
messageBundles: MessageBundleType[],
) {
if (!messageBundles.length) return
)
}
I have issue when I pass on DraggableFlatList data={sections} the drag and drop is working but this part <ScrollView style={{}} contentContainerStyle={{ flexGrow: 1 }}>
<View
style={{
zIndex: 999,
position: "relative",
flex: 1,
justifyContent: "space-between",
}}
>
{/* <View
style={{
// flex: 1,
justifyContent: "space-between",
}}
> /}
<Image
source={AppAssets.images.topBoardBg.uri}
style={styles.imgBgTopLastItem}
resizeMode={"stretch"}
/>
<View
style={{
// flex: 1,
justifyContent: "center",
alignItems: "center",
gap: 30,
}}
>
<Image
source={AppAssets.images.dashboardEmptyPhoto.uri}
style={{ width: 180, height: 120 }}
/>
<Button
containerStyle={{
alignSelf: "center",
position: "relative",
top: 5,
justifyContent: "center",
}}
type="primary"
onPress={() => {
setSectionIdForSectionEdit("last")
if (!member) return
modal.open({
component: (
<ChannelSectionAddEdit
room={room}
section={item.id !== "last" ? item : undefined}
onClose={() => setSectionIdForSectionEdit(null)}
/>
),
background: "pattern",
footer: "rgb",
scrollEnabled: false,
keyboard: 240,
})
}}
>
Add column
<Image
source={AppAssets.images.bottomBoardBg.uri}
style={styles.imgBgBottomLastItem}
resizeMode={"stretch"}
/>
{/ */}
not showing. When I change sections to sectionsDataDrag in data everything is working except drag and drop not working. How to fix it ? Please help me!
The issue you encountered stems from a confusion between the sections and sectionsDataDrag state variables in your DraggableFlatList. You mentioned that when data={sections} is passed to DraggableFlatList, the drag-and-drop functionality works, but the <ScrollView> section does not render correctly. Conversely, when data={sectionsDataDrag} is passed, the <ScrollView> section renders, but drag-and-drop functionality breaks. To address this issue, let's clarify the purpose of these two state variables and how to synchronize them.
Root Cause
It seems like sectionsDataDrag is meant to manage the state for items that can be dragged and reordered, but it's not being updated or utilized correctly to reflect the current state of your sections.
Recommended Solution
To resolve this, ensure that your sectionsDataDrag state is always synchronized with your sections state or consolidate into a single source of truth that manages sections. Based on the provided code snippets and your description, you could take the following approaches:
Single Source of Truth (Preferred): Rather than maintaining two separate states (sections and sectionsDataDrag) that essentially hold the same data, use only one state variable to manage your sections. This reduces complexity and avoids potential synchronization issues.
Synchronize States: If there's a specific reason for maintaining both sections and sectionsDataDrag, ensure they are synchronized. For instance, you can update sectionsDataDrag whenever sections changes (e.g., in the useEffect hook that builds the sections).
Here's how you can approach the first option:
const [sections, setSections] = useState<
(ChannelSectionType & {
messageBundles: MessageBundleType[]
})[]
>([]);
// Remove sectionsDataDrag and only use sections to manage your data
Whenever you perform operations such as adding, removing, or reordering sections, directly update the sections state. Your DraggableFlatList should continue to use data={sections}. Since you are looking to display a custom view (i.e., the <ScrollView> section) when there are no sections available, you can conditionally render that view based on the length of sections.
For instance, before rendering the DraggableFlatList, you can check:
if (sections.length === 0) {
// Render the <ScrollView> custom empty state component
return <YourCustomEmptyStateComponent />;
}
This will show the empty state when there are no sections and show the draggable list when there are sections to display.
Finally, ensure that any updates to the sections (like drag-and-drop operations) update the sections state accordingly to keep the UI in sync.
Additional Notes
Ensure your draggable and other interactive elements are not nested in a way that can cause event conflicts. Sometimes, touchable elements inside a scrollable or draggable area can lead to unexpected behavior.
Regularly test the drag-and-drop functionality after making changes to ensure that the interaction remains intuitive and performant for the user.