react-native-copilot icon indicating copy to clipboard operation
react-native-copilot copied to clipboard

Cannot Show Walkthrough for Header components via React Navigation

Open nikhiltechzillaindiacom opened this issue 6 years ago • 12 comments

I am using react navigation library to manage navigation within my app.I am using this library to enable first time users to get to know the different features of my app.When i try to Wrap a Text element with a CoPilot Step in thestatic navOptionssections(In react-Navigation,this allows the user to customise the header shown on the top of the screen) it gives me an error saying that undefined is not an object(evaluationg this.context._getCurrentStep.)

nikhiltechzillaindiacom avatar May 09 '19 10:05 nikhiltechzillaindiacom

same issue

zidun avatar May 23 '19 10:05 zidun

Same issue. I love this library, and it's really the only one of it's kind for react native. But the fact that all steps in a walkthrough have to be children of the same parent component is extremely limiting.

The demo is somewhat misleading because it suggests you can highlight elements of a footer navigation, but most devs are going to use a framework to get that done (like react-navigation), which currently makes this library unusable.

npedrini avatar Jul 11 '19 12:07 npedrini

I am having the same issue and trying to figure out is there a workaround for using this library in navigationOptions or is there any other library for creating a walkthrough for your app?

nehanilsoni avatar Jul 23 '19 13:07 nehanilsoni

still no workaround for this ?

blazk0 avatar Aug 03 '19 15:08 blazk0

Haven't actually have time to integrate this to our project. My initial idea is to wrap the RootComponent created by react-navigation's createAppContainer with copilot, and then in the child screens, using this.props.start(fromStep)... to start the show. But it seems not possible with the current implementation using legacy context. (https://reactjs.org/docs/legacy-context.html)

Idea to make it possible:

  • In hocs/copilot.js, use the modern context API, exposing the start(), stop() api
  • in the child component, make use of <Copilot.Consumer>, and then you will be able to start the show anywhere within the context.

ptgamr avatar Aug 06 '19 04:08 ptgamr

Unfortunately, that's currently the limitation of this package. I have to admit it was not the best approach to wait for a component to mount in order to register the step for it in the context.

I personally haven't tried this, but one hacky solution can be having separate copilot instances for each screen. Now that you can assign custom labels to copilot buttons, you can change the "Finish" label for the first screen to "Next" and onNext for the last step can jump to the other screen.

mohebifar avatar Aug 06 '19 15:08 mohebifar

@mohebifar What's your recommendation to focus to a button in react-navigation header ? Something like

class HomeScreen extends React.Component {
  static navigationOptions = {
    headerTitle: <LogoTitle />,
    headerRight: (
      <Button
        onPress={() => alert('This is a button!')}
        title="Info"
        color="#fff"
      />
    ),
  };
}

const AppNavigator = createStackNavigator({
  Home: {
    screen: HomeScreen
  }
});

Notice that headerRight is not render as children of HomeScreen... but it will render within react-navigation context

ptgamr avatar Aug 06 '19 23:08 ptgamr

@ptgamr I solved this by using an empty view with position absolute. It doesn't matter that it's not wrapping around the actual component as the highlighted area within a tour is not functional/touchable anyway.

const WalkthroughableView = walkthroughable(View);

  <CopilotStep text="Here's where to tap to view this screen." order={3} name="actionsButton">
    <WalkthroughableView style={{ position: "absolute", top: -40, left: (dimensions.SCREEN_WIDTH * 0.5) - 25, minHeight: 70, width: 80 }}>
    </WalkthroughableView>
  </CopilotStep>

DavidBHanby avatar Nov 07 '19 01:11 DavidBHanby

This workaround sounds like a great idea. I am trying to place it at the bottom of the screen instead, in order to overlay bottom tab navigator buttons, but I am not quite able to achieve that.

Wonder if either of you know how I could reuse this solution to place it on the bottom of the screen.

lrpinto avatar Feb 18 '20 16:02 lrpinto

Unless I've misunderstood, the solution will be the same. By setting { position: 'absolute' } you can also set the 'top' and 'left' properties to any number you want, letting you place it anywhere on the screen, including the bottom.

DavidBHanby avatar Feb 18 '20 16:02 DavidBHanby

Thank you David. Doing that it seemed to be moving the view in relation to the tool-tip. On a second look on the docs I think I found how to shift the main container down.

const screenHeight = Math.round(Dimensions.get('window').height)

export default copilot({ verticalOffset: screenHeight - 98, // <= this worked animated: true, overlay: 'svg' })(RootComponent)

lrpinto avatar Feb 18 '20 16:02 lrpinto

I am using react navigation library to manage navigation within my app.I am using this library to enable first time users to get to know the different features of my app.When i try to Wrap a Text element with a CoPilot Step in thestatic navOptionssections(In react-Navigation,this allows the user to customise the header shown on the top of the screen) it gives me an error saying that undefined is not an object(evaluationg this.context._getCurrentStep.)

Any idea to fix this problem. I trying to use CopilotStep component on "static navigationOptions" and get this error

pbtkhoa avatar Jun 29 '20 09:06 pbtkhoa