Giter Site home page Giter Site logo

gorhom / react-native-portal Goto Github PK

View Code? Open in Web Editor NEW
606.0 6.0 35.0 680 KB

A simplified portal implementation for ⭕️ React Native & Web ⭕️.

License: MIT License

JavaScript 10.99% TypeScript 87.69% Handlebars 1.32%
react-native react portal

react-native-portal's Introduction

React Native Portal

React Native Portal npm npm runs with expo

A simplified portal implementation for ⭕️ React Native ⭕️.

React Native Portal


Features

  • Multi portals handling.
  • Multi portal hosts handling.
  • Allow override functionality.
  • Compatible with React Native Web.
  • Compatible with Expo, check out the project Expo Snack.
  • Written in TypeScript.

Installation

yarn add @gorhom/portal

Usage

Simple Portal

This is the very simple usage of this library, where you will teleport your content to the PortalProvider layer of the app.

First, you will need to add PortalProvider to your root component - this usually be the App.tsx.

export const App = () => (
  <PortalProvider>
  {... your app goes here}
  </PortalProvider>
);

Last, you wrap the content that you want to teleport with Portal.

const BasicScreen = () => {
  return (
    { ... }
    <Portal>
      <Text>
        Text to be teleported to the root host
      </Text>
    </Portal>
    { ... }
  );
};

Custom Portal Host

This is when you need to teleport your content to a custom portal host PortalHost at any layer in the app.

First, you will need to add PortalProvider to your root component - this usually be the App.tsx.

export const App = () => (
  <PortalProvider>
  {... your app goes here ...}
  </PortalProvider>
);

Second, you will need to add PortalHost at any layer in your app, with a custom name.

const CustomView = () => {
  return (
    { ... }
    <PortalHost name="CustomPortalHost" />
    { ... }
  );
};

Last, you wrap the content that you want to teleport with Portal and the custom portal host name.

const BasicScreen = () => {
  return (
    { ... }
    <Portal hostName="CustomPortalHost">
      <Text>
        Text to be teleported to the CustomView component
      </Text>
    </Portal>
    { ... }
  );
};

React Native Screens integration

In order to get your teleported content on top of all native views, you will need to wrap your content with FullWindowOverlay from react-native-screens.

import { FullWindowOverlay } from 'react-native-screens';

const BasicScreen = () => {
  return (
    { ... }
    <Portal>
      <FullWindowOverlay style={StyleSheet.absoluteFill}>
        <Text>
          Text to be teleported to the CustomView component
        </Text>
      </FullWindowOverlay>
    </Portal>
    { ... }
  );
};

React Native Gesture Handler

To avoid issues when using the React Native Portal with React Native Gesture Handler, you must place the PortalProvider under the GestureHandlerRootView, otherwise it might freeze your app.

export const App = () => (
  <GestureHandlerRootView>
    <PortalProvider>
    {... your app goes here}
    </PortalProvider>
  </GestureHandlerRootView>
);

Read more about the app freezing issue.

Props

Portal Props

name

Portal's key or name to be used as an identifer.

required: NO | type: string | default: auto generated unique key

hostName

Host's key or name to teleport the portal content to.

required: NO | type: string | default: 'root'

handleOnMount

Override internal mounting functionality, this is useful if you want to trigger any action before mounting the portal content.

type handleOnMount = (mount?: () => void) => void;

required: NO | type: function | default: undefined

handleOnUnmount

Override internal un-mounting functionality, this is useful if you want to trigger any action before un-mounting the portal content.

type handleOnUnmount = (unmount?: () => void) => void;

required: NO | type: function | default: undefined

children

Portal's content.

required: NO | type: ReactNode | ReactNode[] | default: undefined

PortalHost Props

name

Host's key or name to be used as an identifier.

required: YES | type: string

Hooks

usePortal

To access internal functionalities of all portals.

/**
 * @param hostName host name or key.
 */
type usePortal = (hostName: string = 'root') => {
  /**
   * Register a new host.
   */
  registerHost: () => void;
  /**
   * Deregister a host.
   */
  deregisterHost: () => void;
  /**
   * Add portal to the host container.
   * @param name portal name or key
   * @param node portal content
   */
  addPortal: (name: string, node: ReactNode) => void;
  /**
   * Update portal content.
   * @param name portal name or key
   * @param node portal content
   */
  updatePortal: (name: string, node: ReactNode) => void;
  /**
   * Remove portal from host container.
   * @param name portal name or key
   */
  removePortal: (name: string) => void;
};

Built With ❤️

Author

Sponsor & Support

To keep this library maintained and up-to-date please consider sponsoring it on GitHub. Or if you are looking for a private support or help in customizing the experience, then reach out to me on Twitter @gorhom.

License

MIT


Mo Gorhom Mo Gorhom

react-native-portal's People

Contributors

alansl avatar egadstar avatar gorhom avatar jeremyadavis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

react-native-portal's Issues

FullWindowOverlay and Portal fails on react native fullscreen presentation modal

Whenever you have a react navigation full screen presentation modal, the Button element does not outputs the console.log value

I I remove and leave the rest, it would start working again.

<Portal>
	<FullWindowOverlay>
		<View className="mt-52 h-full w-full bg-red-400">
			<Button title="Hello world" onPress={() => console.log('HELLO')} />
		</View>
	</FullWindowOverlay>

</Portal>

Can not mock <Portal /> using Jest and react-test-renderer

I would like to Mock using jest the component from @gorhom/portal as a View.

I would like to do it because the component require a at the root of the app. But I would like to test a single screen.

This is the mock that I've done:

import { jest } from '@jest/globals'

jest.mock('@gorhom/portal', () => {
  const react = require('react-native')

  return {
    __esModule: true,
    Portal: () => react.View,
    usePortal: jest.fn(),
  }
})

But when I call in my test my screen this is the error I have:

'PortalDispatchContext' cannot be null, please add 'PortalProvider' to the root component.

       7 |
       8 | test('renders correctly', () => {
    >  9 |   const tree = renderer.create(<CreateAccount />).toJSON()
         |                         ^
      10 |   expect(tree).toMatchSnapshot()
      11 | })
      12 |

And the component causing this issue is this one:

const Modal = () => {

  ...

  return (
    <Portal>
      <BottomSheet>
        {...}
      </BottomSheet>
    </Portal>
  )
}

If you have any idea (this is the so post related: https://stackoverflow.com/questions/75286623/set-portal-from-gorhom-portal-as-view-using-mock-in-jest)

Is there a way to dynamically add some node in Portal?

I tried to design some functionalities like Modal.alertModal.confirm,which when developers call Modal.alert, it would display an alert modal programmatically.

export default function alert(props: AlertProps) {
    Portal.add(<AlertModal {...props} />);
}

is there a way to do so? Thanks

External contexts don't work inside modal bottom sheet

Hi, thanks for your hard work. I'm on 2.0.3, with Expo SDK 40.

Consider the following:

<ExternalProvider>
    <BottomSheetModalProvider>
        <App/>
    </BottomSheetModalProvider>
</ExternalProvider>

inside <App/>:

const App = () => {
    const externallyProvidedStuff = useExternalContext() 

    return <OtherStuff/>
}

externallyProvidedStuff is coming up as null. It's happening for React Navigation as well as our own custom context hooks, which worked with other libraries.

I am wondering if this is something particular to your Portal library. We wrote something similar last year, actually, and abandoned it for this problem.

Have you heard this from any other users?

Portal not displayed when it's inside BottomSheetModal

I have an App with a TabNavigator and in one of the Tab screens I display a BottomSheetModal. The provider for this BottomSheetModal is in the same screen, since I want the model to be displayed behind the TabBar.

But I also have a Portal in the model which I want to display above the TabBar, so I placed my PortalProvider and PortalHost outside of the screen above my TabNavigator, notably above the BottomSheetModalProvider.
When the Portal has no custom hostname it uses the BottomSheetModalProvider as the PortalProvider, which I expected, since BottomSheetModalProvider wraps a PortalProvider.

But when a hostName is specified (see example below) the Portal is not displayed at all, like the PortalHost couldn't be found. So it skips the BottomSheetModalProvider but does not find the PortalHost above it.

<App>
  <PortalProvider>
    <TabNavigator>
      <TabScreen/>
    <TabNavigator/>
    <PortalHost name="AboveTabBar" />

An example screen in the TabNavigator:

const TabScreen = () => {
  return (
    <BottomSheetModalProvider>
      <Portal hostName="AboveTabBar">
        <Text>test</Text>
      </Portal>
      <BottomSheetModal>
        ...
      </BottomSheetModal>
    </BottomSheetModalProvider>
  )
}

Could this be fixed by using a custom hostName inside BottomSheetModalProvider, so that custom portals don't use that as the host?

Keeping only last Portal node in PortalHost

Hi,

For a use case with a deep hierarchy, I wanted to only keep the last element portaled to PortalHost.
So my solution was to create this component:

import type { PortalHostProps } from '@gorhom/portal/src/components/portalHost/types';
import { usePortalState } from '@gorhom/portal/src/hooks/usePortalState';
import { memo, useEffect } from 'react';

const PortalHostUniqueComponent = ({ name }: PortalHostProps) => {
    //#region hooks
    const state = usePortalState(name);
    const { registerHost, deregisterHost } = usePortal(name);
    //#endregion

    //#region effects
    useEffect(() => {
        registerHost();
        return () => {
            deregisterHost();
        };
        // eslint-disable-next-line react-hooks/exhaustive-deps
    }, []);
    //#endregion

    //#region render
    return <>{state.length > 0 ? state[state.length - 1].node : null}</>;
    //#endregion
};

export const PortalHostUnique = memo(PortalHostUniqueComponent);
PortalHostUnique.displayName = 'PortalHostUnique';

The only real change is the return line, only keeping the last node added.

return <>{state.length > 0 ? state[state.length - 1].node : null}</>;

Now I can have a default portal that will be overrided by deeper portals.
Maybe it could also be a boolean property on PortalHost like "unique"?

Error `__DEV__ is not defined` on Web if not patched manually in webpack

There are a couple of raw checks on __DEV__ in logger.ts that will cause a hard crash if @gorhom/portals is used in a default React Native Web build. The cause is that React Native Web doesn't define a global __DEV__ variable like React Native does.

Many libraries avoid this by doing a check that doesn't presume the existence of the global variable, e.g. if (typeof __DEV__ !== 'undefined' && __DEV__) instead of if (__DEV__).

Individual apps could work around having dependencies like this that do raw checks on __DEV__ by implementing their own webpack plugins to rewrite __DEV__ and then apply this to the appropriate modules in their build; but this can be a problem if using this library in a shared package like a components library, because it forces every consumer to add this config to their web builds, which can be difficult in some environments.

I'm happy to put up a PR for this [edit] - #30

👀

I hope there's web support in mind for this. Can't wait to see it...

[portal][FlatList] - Overload style issue ?

I'm working on a react-native + expo application. I have a screen Home with a fox template (.glb with react-three/fiber) in the middle and a Navbar at the bottom. I have a button in my Navbar which allows me to unfold a Modal (ClothesScreen) which takes up 30% of the bottom of the screen (enough to display content and to leave the fox visible in the background). In this Modal I have a FlatList of items. I'm trying to make an item from the FlatList draggable to the fox modele.

My problem: I use react-native-gesture-handler and react-native-reanimated to make my item draggable but when I drag my item outside the FlatList it goes below all the content. I tried to fix the problem using zIndex but it didn't work at all. I tried using Portals (@gorhom/portal) which fixed my problem but made my FlatList unusable because Portals seem to overload its style, displaying the items vertically when I want them horizontally ect.... I haven't found a solution to correct this problem, does anyone have any ideas on this style problem?

Keyboard on Android?

It seems like the <Portal /> view shrinks when the keyboard comes up - it isn't the full height of the screen, it's only what's visible. The opposite is the case for iOS.

Is this expected behavior?

Cant swipe my modal

Hello,

I use react-native-modalize and portal. I cant swipe my modal when I am using it with portal. Why?

Works:

  <GestureHandlerRootView>
    <Tabs.FlatList
      data={reviewsTabs} 
      renderItem={RenderItem} 
      keyExtractor={(item, i) => item.id.toString()}
      initialNumToRender={9}
      style={s.flatList}
      contentContainerStyle={s.flatListContent}
      getItemLayout={(data, index) => ({
        length: 333, offset: 150 * index, index
      })}
      maxToRenderPerBatch={200}
      updateCellsBatchingPeriod={50}
    />

      <ModalReview ref={modalReviewRef} onPress={handleSendModalReview} />

  </GestureHandlerRootView>

Not working:

  <GestureHandlerRootView>
    <Tabs.FlatList
      data={reviewsTabs} 
      renderItem={RenderItem} 
      keyExtractor={(item, i) => item.id.toString()}
      initialNumToRender={9}
      style={s.flatList}
      contentContainerStyle={s.flatListContent}
      getItemLayout={(data, index) => ({
        length: 333, offset: 150 * index, index
      })}
      maxToRenderPerBatch={200}
      updateCellsBatchingPeriod={50}
    />
  
  <Portal>
      <ModalReview ref={modalReviewRef} onPress={handleSendModalReview} />
  </Portal>

  </GestureHandlerRootView>

Using a portals in a package which include in another package

Hi, first of all, thanks for this amazing library. I use portals in a package A that I want to share/include in another package B. The package A works well with the portal but when I wanna use it with package B it gives me the error

Uncaught Error: 'PortalStateContext' cannot be null, please add 'PortalProvider' to the root component.

Do I really have to add <PortalProvider> also to package B? I really would like to avoid this dependency. Also even if I add it, it still shows me this error. The package A component which I use in package B already uses <PortalProvider>.

I also wonder why your example app doesn't use the PortalProvider at all.

Couldn't find a navigation object

Hey I've tried to use this library but got issues with navigation, it is like navigation is lost somewhere.

For reference I use useNavigation everywhere.

Screen Shot 2022-07-15 at 11 42 14

App freeze on android

portal package on ios works fine,but on android app freeze.
i use react-navigation and react-native-reanimated

Nesting Portals

Hi,

Is it possible to nest Portals?

Getting the following error:

Error: 'PortalStateContext' cannot be null, please add 'PortalProvider' to the root component.

Portal not placed over react native navigation tabs

As noticed in the below image, my portal, which is the red background with the input, is placed inbetween the navigation view, I want it to be teleported above everything.

The host is placed in App.tsx like this

<PortalProvider>
      <InternetProvider>
        <StatusBar
          animated
          backgroundColor={colorScheme === 'dark' ? 'white' : 'black'}
          barStyle={colorScheme === 'dark' ? 'light-content' : 'dark-content'}
        />
        <UserProvider>
          <NativeBaseProvider>
            <ApolloProvider client={client}>
              <SafeAreaProvider>
                <NavigationContainer>
                  <Stack.Navigator screenOptions={{ gestureEnabled: false }}>
                    <Stack.Screen
                      options={{ headerShown: false }}
                      name="MainPage"
                      component={MainPage}
                    />
                    <Stack.Screen
                      name="MusterHalle"
                      options={{ title: 'Muster Halle' }}
                      component={MusterHallePage}
                    />
                    <Stack.Screen name="Ersatz" component={ErsatzPage} />
                  </Stack.Navigator>
                </NavigationContainer>
              </SafeAreaProvider>
            </ApolloProvider>
          </NativeBaseProvider>
          <Toast />
          <PortalHost name="mainPortal" />
        </UserProvider>
      </InternetProvider>
    </PortalProvider>

Any idea how could I achieve what I am trying to do?

image

External Portals don't work inside BottomSheetModals

Hi, thanks for your hard work. I'm on 2.0.3, with Expo SDK 40.

Consider the following:

<ExternalProvider>
    <BottomSheetModalProvider>
        <App/>
    </BottomSheetModalProvider>
</ExternalProvider>

inside <App/>:

const App = () => {
    return (
        <BottomSheetModal>
            <OtherStuff/>
        </BottomSheetModal/>
    )
}

const OtherStuff = () => {
    const externalllyProvidedStuff = useExternalContext()
    return <EvenMoreStuff/>
}

externallyProvidedStuff is coming up as null when it shouldn't. It's happening for React Navigation as well as our own custom context hooks, which worked with other libraries.

I am wondering if this is something particular to your Portal library. We wrote something similar last year, actually, and abandoned it for this problem.

Have you heard this from any other users?

Context doesn't behave as expected

Hey!

I come from ReactDOM land where ReactDOM.createPortal exists and I see this library as the react-native alternative.

One key behaviour of ReactDOM.createPortal that I've come to expect, is that a rendered component that is portaled, maintains the context of where the element was defined.

See this issue for an example enesozturk/react-native-hold-menu#82 (comment)

I can also see confusion about this behaviour in #2, #3 and #31. The workaround seems to be to either re-order context providers. I have some cases where that is not feasible.

I dove into the source and understand why the behaviour is as it is.

@gorhom, have you thought about this previously? Is there a way to arrive at this behaviour without some sort of first-class implementation by react or react-native?

Portal + BottomSheet release crash

  "@gorhom/bottom-sheet": "3.3.1",
  "@gorhom/portal": "1.0.2",

If I use 1.0.2 version of portal library, and wrap my BottomSheet into <Portal host="...">...</Portal> everything works fine in debug configuration on iOS. BUT when I try a release build it crashes as soon as I render <Portal /> part. If I render non bottom-sheet related components inside portal, they render fine and no errors occur.

image

I've downgraded to 0.2.0 version of the library and it seems to be working fine. Is it somehow related to immer?

Flicker appears on keyboard close in form page.

We are using Portal as well as Bottomsheet in the Application. Portal specifically for showing bottomsheet above bottomBar in HomePage. In Form Page after editing fields or pressing back while editing (closing keyboard) a flicker appears i.e., backdrop defined in bottomsheet. As mentioned in below stackoverflow post for Flicker we added View with device height as parent to all in App.tsx. But after that, textfields in forms not scrolled above keyboard i.e, (softInputMode = adjustResize in android manifest not working)

Portal does not render when unmounting `PortalHost` and remounting again

Awesome library @gorhom!

In my use-case, I conditionally render a <PortalHost>. This works on the first time, but after unmounting it and mounting it again, the Portal inside does not render anymore.

I'd love to provide a reproduceable example, but unfortunately the codebase is very nested and WIP right now, if you have trouble reproducing this I could try patching something together..

Thanks!

I need help with handling state changes coming from another component

I tried creating a Confirmation Dialog that will be shown to the user.

It works with static data, but if I want to get user input for example, state won't re-render the data in portal.

If I create some JSX code with state too, for example a controlled input. Then pass this state to my function and create a portal with that JSX, when I type in the controlled input, state updates but component from Portal does not re-render to reflect the updated state.

It works only if the state is inside the Portal's component, if passed as props, it won't re-render

Here is my custom hook that displays the dialog and then waits for the user to press yes or no in the dialog.

https://gist.github.com/andreiwow2/4739fe71c3d98b612c13db6c10068a3c

RangeError - Maximum call stack size exceeded.

Hi there,

I liked the API design of this library and decided to use it together with react-native-modalize. It worked well locally, but in distribution builds the below error caused crashes on both iOS and Android.

I switched to another library and unfortunately can't put time into creating a bare minimum reproducible case. But I thought I'd share it!

RangeError
Maximum call stack size exceeded.

    node_modules/immer/dist/immer.esm.js:1:712 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588

[BottomSheetModal] [BottomSheetFlatList] Persist last scroll position on the flatlist when reopening the bottom sheet modal again

Hi,

I have a bottom sheet modal which renders a flatlist inside. A user presses an item on the flatlist and the bottom sheet closes. When the bottom sheet is opened again, the flatlist starts from the top. That is the scroll position is reset. I'd like it to persist such that when a user selects something from the bottom of the flatlist, it remains in the scroll position the next time too.

I tried the props scrollsToTop={false} but it isn't working.

<BottomSheetModal
      ref={bottomSheetModalRef}
      snapPoints={snapPoints}
      handleIndicatorStyle={{ display: 'none' }}
      backdropComponent={CustomBackdrop}>
      <BottomSheetFlatList
        data={SESSIONS}
        renderItem={renderItem}
        scrollsToTop={false}
      />
    </BottomSheetModal>

Warning: componentWillMount has been renamed, and is not recommended for use

I'm getting the following warning when I use PortalProvider.

"react": "17.0.2",
"react-native": "^0.65.1",
"react-native-portal": "^1.3.0",

Warning: componentWillMount has been renamed, and is not recommended for use. See https://reactjs.org/link/unsafe-component-lifecycles for details.

  • Move code with side effects to componentDidMount, and set initial state in the constructor.
  • Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run npx react-codemod rename-unsafe-lifecycles in your project source folder.

Please update the following components: PortalProvider

bundling failed: SyntaxError

This is how it explodes when I include portal in my project. (the project was not written with typescript)

error: bundling failed: SyntaxError: <PROJECT_PATH>/node_modules/@gorhom/portal/src/components/portal/Portal.tsx: Unexpected token (4:12)

  2 | import { nanoid } from 'nanoid/non-secure';
  3 | import { usePortal } from '../../hooks';
> 4 | import type { PortalProps } from './types';

Failed to remove portal

"@gorhom/portal": "^1.0.0"

I keep getting the following error in React Native

Failed to remove portal '1mrgf5_Wbp0kwl8wjzX1w', 'autocomplete_section_list' was not registered!
at PortalProviderComponent

Here is the snippet of code where the issue occurs

          <React.Fragment>
                <PortalHost name="autocomplete_section_list" />
                <View style={{ marginBottom: 10 }}>
                    <TextInput
                        autoFocus
                        isDisabled={isDisabled}
                        isRequired={isRequired}
                        label={label}
                        value={value}
                        placeholder={placeholder}
                        onChangeText={onChange}
                        onFocus={() => setHideResults(false)}
                        onBlur={onBlurTextInput}
                        startAdornment={startAdornment}
                        endAdornment={endAdornment}
                        style={style}
                    />
                    {
                        isFetching && (
                            <View style={[theme.selectList, styles.sectionList, styles.loading]}>
                                <Text style={theme.text}>Loading...</Text>
                            </View>
                        )
                    }
                    {
                        !hideResults && !isFetching && (
                            <Portal hostName="autocomplete_section_list">
                                <View style={styles.sectionList}>
                                    <SectionList
                                        sections={options}
                                        keyExtractor={(item) => item.label}
                                        renderItem={renderOption}
                                        renderSectionHeader={renderSectionHeader}
                                        keyboardShouldPersistTaps="always"
                                    />
                                </View>
                            </Portal>
                        )
                    }
                </View>
            </React.Fragment>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.