Home button scrolls to top when on home page
parent
8dc8200f07
commit
d7a75a2062
|
@ -1,4 +1,4 @@
|
||||||
import React from 'react'
|
import React, {MutableRefObject} from 'react'
|
||||||
import {observer} from 'mobx-react-lite'
|
import {observer} from 'mobx-react-lite'
|
||||||
import {Text, View, FlatList, StyleProp, ViewStyle} from 'react-native'
|
import {Text, View, FlatList, StyleProp, ViewStyle} from 'react-native'
|
||||||
import {FeedModel, FeedItemModel} from '../../../state/models/feed-view'
|
import {FeedModel, FeedItemModel} from '../../../state/models/feed-view'
|
||||||
|
@ -7,9 +7,11 @@ import {FeedItem} from './FeedItem'
|
||||||
export const Feed = observer(function Feed({
|
export const Feed = observer(function Feed({
|
||||||
feed,
|
feed,
|
||||||
style,
|
style,
|
||||||
|
scrollElRef,
|
||||||
}: {
|
}: {
|
||||||
feed: FeedModel
|
feed: FeedModel
|
||||||
style?: StyleProp<ViewStyle>
|
style?: StyleProp<ViewStyle>
|
||||||
|
scrollElRef?: MutableRefObject<FlatList<any> | null>
|
||||||
}) {
|
}) {
|
||||||
// TODO optimize renderItem or FeedItem, we're getting this notice from RN: -prf
|
// TODO optimize renderItem or FeedItem, we're getting this notice from RN: -prf
|
||||||
// VirtualizedList: You have a large list that is slow to update - make sure your
|
// VirtualizedList: You have a large list that is slow to update - make sure your
|
||||||
|
@ -30,6 +32,7 @@ export const Feed = observer(function Feed({
|
||||||
{feed.hasError && <Text>{feed.error}</Text>}
|
{feed.hasError && <Text>{feed.error}</Text>}
|
||||||
{feed.hasContent && (
|
{feed.hasContent && (
|
||||||
<FlatList
|
<FlatList
|
||||||
|
ref={scrollElRef}
|
||||||
data={feed.feed.slice()}
|
data={feed.feed.slice()}
|
||||||
keyExtractor={item => item._reactKey}
|
keyExtractor={item => item._reactKey}
|
||||||
renderItem={renderItem}
|
renderItem={renderItem}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import React from 'react'
|
import React, {MutableRefObject} from 'react'
|
||||||
|
import {FlatList} from 'react-native'
|
||||||
import {IconProp} from '@fortawesome/fontawesome-svg-core'
|
import {IconProp} from '@fortawesome/fontawesome-svg-core'
|
||||||
import {Home} from './screens/Home'
|
import {Home} from './screens/Home'
|
||||||
import {Search} from './screens/Search'
|
import {Search} from './screens/Search'
|
||||||
|
@ -15,6 +16,7 @@ import {Settings} from './screens/Settings'
|
||||||
export type ScreenParams = {
|
export type ScreenParams = {
|
||||||
params: Record<string, any>
|
params: Record<string, any>
|
||||||
visible: boolean
|
visible: boolean
|
||||||
|
scrollElRef: MutableRefObject<FlatList<any> | undefined>
|
||||||
}
|
}
|
||||||
export type Route = [React.FC<ScreenParams>, IconProp, RegExp]
|
export type Route = [React.FC<ScreenParams>, IconProp, RegExp]
|
||||||
export type MatchResult = {
|
export type MatchResult = {
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
import React, {useState, useEffect, useMemo} from 'react'
|
import React, {useState, useEffect, useMemo} from 'react'
|
||||||
import {useSharedValue} from 'react-native-reanimated'
|
|
||||||
import {View} from 'react-native'
|
import {View} from 'react-native'
|
||||||
import {observer} from 'mobx-react-lite'
|
import {observer} from 'mobx-react-lite'
|
||||||
import {Feed} from '../com/posts/Feed'
|
import {Feed} from '../com/posts/Feed'
|
||||||
import {FAB} from '../com/util/FloatingActionButton'
|
import {FAB} from '../com/util/FloatingActionButton'
|
||||||
import {Selector} from '../com/util/Selector'
|
|
||||||
import {useStores} from '../../state'
|
import {useStores} from '../../state'
|
||||||
import {FeedModel} from '../../state/models/feed-view'
|
import {FeedModel} from '../../state/models/feed-view'
|
||||||
import {ComposePostModel} from '../../state/models/shell'
|
import {ComposePostModel} from '../../state/models/shell'
|
||||||
import {ScreenParams} from '../routes'
|
import {ScreenParams} from '../routes'
|
||||||
import {s} from '../lib/styles'
|
import {s} from '../lib/styles'
|
||||||
|
|
||||||
export const Home = observer(function Home({visible}: ScreenParams) {
|
export const Home = observer(function Home({
|
||||||
|
visible,
|
||||||
|
scrollElRef,
|
||||||
|
}: ScreenParams) {
|
||||||
const store = useStores()
|
const store = useStores()
|
||||||
const [hasSetup, setHasSetup] = useState<boolean>(false)
|
const [hasSetup, setHasSetup] = useState<boolean>(false)
|
||||||
const [selectedViewIndex, setSelectedViewIndex] = useState<number>(0)
|
|
||||||
const defaultFeedView = useMemo<FeedModel>(
|
const defaultFeedView = useMemo<FeedModel>(
|
||||||
() =>
|
() =>
|
||||||
new FeedModel(store, 'home', {
|
new FeedModel(store, 'home', {
|
||||||
|
@ -43,13 +43,10 @@ export const Home = observer(function Home({visible}: ScreenParams) {
|
||||||
const onCreatePost = () => {
|
const onCreatePost = () => {
|
||||||
defaultFeedView.loadLatest()
|
defaultFeedView.loadLatest()
|
||||||
}
|
}
|
||||||
const onSelectView = (viewIndex: number) => {
|
|
||||||
setSelectedViewIndex(viewIndex)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={s.flex1}>
|
<View style={s.flex1}>
|
||||||
<Feed key="default" feed={defaultFeedView} />
|
<Feed key="default" feed={defaultFeedView} scrollElRef={scrollElRef} />
|
||||||
<FAB icon="pen-nib" onPress={onComposePress} />
|
<FAB icon="pen-nib" onPress={onComposePress} />
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import React, {useState, useEffect} from 'react'
|
import React, {useState, useEffect, useRef} from 'react'
|
||||||
import {observer} from 'mobx-react-lite'
|
import {observer} from 'mobx-react-lite'
|
||||||
import {
|
import {
|
||||||
useWindowDimensions,
|
useWindowDimensions,
|
||||||
|
FlatList,
|
||||||
GestureResponderEvent,
|
GestureResponderEvent,
|
||||||
Image,
|
|
||||||
SafeAreaView,
|
SafeAreaView,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
Text,
|
Text,
|
||||||
|
@ -97,6 +97,7 @@ export const MobileShell: React.FC = observer(() => {
|
||||||
const [isLocationMenuActive, setLocationMenuActive] = useState(false)
|
const [isLocationMenuActive, setLocationMenuActive] = useState(false)
|
||||||
const [isMainMenuActive, setMainMenuActive] = useState(false)
|
const [isMainMenuActive, setMainMenuActive] = useState(false)
|
||||||
const [isTabsSelectorActive, setTabsSelectorActive] = useState(false)
|
const [isTabsSelectorActive, setTabsSelectorActive] = useState(false)
|
||||||
|
const scrollElRef = useRef<FlatList | undefined>()
|
||||||
const winDim = useWindowDimensions()
|
const winDim = useWindowDimensions()
|
||||||
const swipeGestureInterp = useSharedValue<number>(0)
|
const swipeGestureInterp = useSharedValue<number>(0)
|
||||||
const screenRenderDesc = constructScreenRenderDesc(store.nav)
|
const screenRenderDesc = constructScreenRenderDesc(store.nav)
|
||||||
|
@ -109,7 +110,13 @@ export const MobileShell: React.FC = observer(() => {
|
||||||
|
|
||||||
const onPressBack = () => store.nav.tab.goBack()
|
const onPressBack = () => store.nav.tab.goBack()
|
||||||
const onPressForward = () => store.nav.tab.goForward()
|
const onPressForward = () => store.nav.tab.goForward()
|
||||||
const onPressHome = () => store.nav.navigate('/')
|
const onPressHome = () => {
|
||||||
|
if (store.nav.tab.current.url === '/') {
|
||||||
|
scrollElRef.current?.scrollToOffset({offset: 0})
|
||||||
|
} else {
|
||||||
|
store.nav.navigate('/')
|
||||||
|
}
|
||||||
|
}
|
||||||
const onPressMenu = () => setMainMenuActive(true)
|
const onPressMenu = () => setMainMenuActive(true)
|
||||||
const onPressTabs = () => setTabsSelectorActive(true)
|
const onPressTabs = () => setTabsSelectorActive(true)
|
||||||
|
|
||||||
|
@ -184,7 +191,11 @@ export const MobileShell: React.FC = observer(() => {
|
||||||
styles.screen,
|
styles.screen,
|
||||||
current ? swipeTransform : undefined,
|
current ? swipeTransform : undefined,
|
||||||
]}>
|
]}>
|
||||||
<Com params={params} visible={true} />
|
<Com
|
||||||
|
params={params}
|
||||||
|
visible={true}
|
||||||
|
scrollElRef={current ? scrollElRef : undefined}
|
||||||
|
/>
|
||||||
</Animated.View>
|
</Animated.View>
|
||||||
</Screen>
|
</Screen>
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,11 +4,11 @@ Paul's todo list
|
||||||
- Update to RN 0.70
|
- Update to RN 0.70
|
||||||
- Cache some profile/userinfo lookups
|
- Cache some profile/userinfo lookups
|
||||||
- Cursor behaviors on all views
|
- Cursor behaviors on all views
|
||||||
|
- Home button should scroll to top
|
||||||
- Onboarding flow
|
- Onboarding flow
|
||||||
- *
|
- *
|
||||||
- Private beta
|
- Private beta
|
||||||
- Users list
|
- Users list
|
||||||
- Firehose
|
|
||||||
- Linking
|
- Linking
|
||||||
- Web linking
|
- Web linking
|
||||||
- App linking
|
- App linking
|
||||||
|
@ -20,4 +20,4 @@ Paul's todo list
|
||||||
- Bugs
|
- Bugs
|
||||||
- Check that sub components arent reloading too much
|
- Check that sub components arent reloading too much
|
||||||
- Titles are getting screwed up (possibly swipe related)
|
- Titles are getting screwed up (possibly swipe related)
|
||||||
- Home feed not showing own posts
|
- Home feed sizing is off now
|
Loading…
Reference in New Issue