Closed PedroBern closed 3 years ago
The Expo app for the example from this branch is ready!
expo.io/@pedrobern/react-native-collapsible-tab-view-demos?release-channel=pr-58
Hey, so I wanted to try this but it seems that when adding it as a git dependency, it fails to build:
[96msrc/Navigator/createCollapsibleNavigator.tsx[0m:[93m34[0m:[93m10[0m - [91merror[0m[90m TS2742: [0mThe inferred type of 'createCollapsibleNavigator' cannot be named without a reference to 'react-native/node_modules/@types/react'. This is likely not portable. A type annotation is necessary.
[7m34[0m function createCollapsibleNavigator<T extends ParamListBase>() {
[7m [0m [91m ~~~~~~~~~~~~~~~~~~~~~~~~~~[0m
[96msrc/Navigator/createCollapsibleNavigator.tsx[0m:[93m34[0m:[93m10[0m - [91merror[0m[90m TS4058: [0mReturn type of exported function has or is using name 'AnimatedNode' from external module "react-native-reanimated" but cannot be named.
[7m34[0m function createCollapsibleNavigator<T extends ParamListBase>() {
[7m [0m [91m ~~~~~~~~~~~~~~~~~~~~~~~~~~[0m
Found 2 errors.
The version I was using previously worked via its prepare script, something probably regressed in that area.
"react-native-collapsible-tab-view": "PedroBern/react-native-collapsible-tab-view#feat-react-navigation",
As a quick repro (I'm using yarn 2):
Make sure you have a recent yarn 1 version:
npm install -g yarn
cd `mktemp -d` # switch to a temp dir
yarn init -2 # init on yarn v2
yarn config set nodeLinker node-modules
yarn config set enableInlineBuilds true # makes error easier to see
yarn add react-native-collapsible-tab-view@PedroBern/react-native-collapsible-tab-view#feat-react-navigation
Easier repro:
I cloned the branch this PR is based on. Running yarn prepack
results in the errors above.
I found this on StackOverflow, same error with a different package, maybe the second answer help
I will try to reproduce here
Same error here 😞 I will investigate
try now, should work
You can fix one of the errors by removing @types/react
from devDependencies
which shouldn't be needed I think. @types/react-native
has react types already. In my RN projects I don't add @types/react
.
The problem with the latest commit is that it loses all types, so code completion won't work
You can fix one of the errors by removing @types/react from devDependencies which shouldn't be needed I think. @types/react-native has react types already. In my RN projects I don't add @types/react.
Thanks for the suggestion, I will do it
The problem with the latest commit is that it loses all types, so code completion won't work
Yes I know, I will fix it. Was just a quick workaround.
The other error seems to originate from the ScrollView
export, aka these two:
// Tabs.FlatList
// Tabs.ScrollView
I haven't looked too deeply into the changes, but why are they reexported from here?
To clarify, this diff resolves the build error:
diff --git a/package.json b/package.json
index ee3aef7..b40c5d1 100644
--- a/package.json
+++ b/package.json
@@ -48,7 +48,6 @@
"@react-native-community/bob": "^0.16.2",
"@react-navigation/native": "^5.9.2",
"@release-it/conventional-changelog": "^1.1.4",
- "@types/react": "^16.9.44",
"@types/react-native": "0.63.4",
"babel-jest": "^26.2.2",
"babel-preset-react-native": "^4.0.0",
diff --git a/src/Navigator/createCollapsibleNavigator.tsx b/src/Navigator/createCollapsibleNavigator.tsx
index d784e83..4106944 100644
--- a/src/Navigator/createCollapsibleNavigator.tsx
+++ b/src/Navigator/createCollapsibleNavigator.tsx
@@ -32,12 +32,7 @@ import {
} from './types'
function createCollapsibleNavigator<T extends ParamListBase>() {
- const {
- FlatList,
- ScrollView,
- Container,
- useTabsContext,
- } = createCollapsibleTabs<keyof T>()
+ const { Container, useTabsContext } = createCollapsibleTabs<keyof T>()
const Context = React.createContext<TabOptionsContext<keyof T> | undefined>(
undefined
@@ -234,8 +229,6 @@ function createCollapsibleNavigator<T extends ParamListBase>() {
return {
Navigator,
Screen,
- FlatList,
- ScrollView,
useTabsContext,
useTabOptionsContext,
}
diff --git a/yarn.lock b/yarn.lock
index d6a29fa..3399904 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2058,14 +2058,6 @@
"@types/prop-types" "*"
csstype "^3.0.2"
-"@types/react@^16.9.44":
- version "16.14.2"
- resolved "https://registry.yarnpkg.com/@types/react/-/react-16.14.2.tgz#85dcc0947d0645349923c04ccef6018a1ab7538c"
- integrity sha512-BzzcAlyDxXl2nANlabtT4thtvbbnhee8hMmH/CcJrISDBVcJS1iOsP1f0OAgSdGE0MsY9tqcrb9YoZcOFv9dbQ==
- dependencies:
- "@types/prop-types" "*"
- csstype "^3.0.2"
-
"@types/responselike@*", "@types/responselike@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@types/responselike/-/responselike-1.0.0.tgz#251f4fe7d154d2bad125abe1b429b23afd262e29"
But not sure if removing those is correct.
Yes, I just saw it too, the error comes from scroll view. We need to re-export because they are "connected" to the onScroll of each tab. The Tabs.ScrollView
knows if the parent component/tab is focused or not, allowing the Tabs.Container
to track the correct y position (from the currently focused tab) and know how to calculate the offset.
now it's fixed 👍
- export type ScrollViewProps = ComponentProps<typeof Animated.ScrollView>
+ export type ScrollViewProps = ComponentProps<typeof ScrollView>
I probably need to open a new issue, but...
I just tried v3 for the first time in Expo on my iPhone, and I'm seeing this:
Also the snap example doesn't snap at all, and I cannot tap the tab titles to change pages (they don't do anything, only swiping does)
I'm on this branch, but it doesn't seem related to it. I could try main
as well.
Actually it only snaps if momentum scrolling rests within the header.
But if I manually scroll and lift the finger with the header partly visible it doesn't snap. And the scroll positions of the other tabs are not synced, so they end up like the screenshot above.
Didn't test Android. It was quite tricky to get all of these right on iOS on the initial version I contributed to.
In its current state it seems a bit broken on iOS unfortunately :(
There are some other issues as well, such as overscrolling not working any more. Overscrolling is somewhat important to make scrollviews feel native on iOS, otherwise they just abruptly stop at the end, without the nice bounce.
I'll try to take a look at some of these over the weekend.
😞 I'm sorry to hear that. My mac mini is arriving in 2 weeks 🎉 so I will be able to investigate further, but as always, all the help is appreciated. Also, if we can't make it better, we can revert to v2...
@PedroBern I'm sure we can get v3 to work. I think a lot of issues are connected together?
@PedroBern I'm sure we can get v3 to work. I think a lot of issues are connected together?
Finally, with #65 or #67, we are getting there 🎉
I'd like to give this another try, but looks like it needs to be rebased.
yes sure, also I saw it is broken with diffClamp, don't know why. I need to go away right now and will take some hours to get back, then I resolve all these conflicts.
@andreialecu it's up to date now. I need to update the example app to have 2 screens, one with react-navigation examples and the other without it. Both screens with the same set of demos/examples.
@andreialecu see this note on going back
Seems this is a bigger breaking change than I anticipated. Will need to go through the example and docs.
There are a bunch of things missing that I noticed at first glance:
sceneContainerStyle
tabBarLabel
Actually all the props of Navigator
seem to be missing. Including the other one visible in the screenshot (collapsibleOptions
)
Ok, I see they're direct properties. Except animatedValue
which I wasn't able to find yet. 🤔
It's brand new, has nothing to do with the v1/v2, I have built from the ground...
There isn't animatedValue. This may be a problem, since we have many shared values now, instead of the animatedValue.
The solution can be making some shared values controlled, just like refs. But it will be a change in the raw tabs, not the navigator.
I know that - thought it would keep the API more or less though 🙂
I'm leaving some more comments here as I go:
It appears that when changing Animated.FlatList
into TabsNavigator.FlatList
some problems appear:
Animated.FlatList
TabsNavigator.FlatList
item
gets typed as unknown
. ref
doesn't seem to exist.
ref doesn't seem to exist.
This ref will be the same as in the refMap, you already have it.
item gets typed as unknown
Try passing the type explicitly to the flatlist <TabsNavigator.FlatList<ItemType> ... />
, should work, but it also should work implicity 🤔
This ref will be the same as in the refMap, you already have it.
Seems it might be a little tricky to pass it down since the refMap
is defined in the parent, and these are separate individual components. 🤔
It's likely I'm doing things wrong though, it's late here. Will need to revisit this when I'm less tired. Will take another look tomorrow. 🙂
Seems it might be a little tricky to pass it down since the refMap is defined in the parent, and these are separate individual components. 🤔
You can get from the context useTabsContext
🙂
Try passing the type explicitly to the flatlist
<TabsNavigator.FlatList<ItemType> ... />
, should work, but it also should work implicity 🤔
This didn't seem to work btw. Tried <any>
without success. I didn't look to deeply into it, but it's possible something is wrong with the types generated by bob
.
Just out of curiosity, whats the current status on react-navigation
integration for v4? Is it still something you are planning to add?
@yfunk not anytime soon, maybe in the future. If you want to work on a PR would be awesome :) As a starting point you can see the createCollapsibleNavigator from this branch, but keep in mind it was built on top of v3
, so it needs an update.
react-navigation support on v3 🎉
I will update the readme and improve the examples before merging
@andreialecu
Closes #64 Closes #71