Skip to content
This repository has been archived by the owner on Feb 25, 2020. It is now read-only.

feat: pass current opacity to renderIcon prop in CrossFadeIcon #220

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

yassinecc
Copy link

@yassinecc yassinecc commented Nov 17, 2019

Motivation

I was trying to animate a bottom tab bar in the same fashion as the Google Play Store app does. My plan was to use Lottie animations with react-navigation's createBottomTabBar.

const ActiveLottie = props => {
  const lottieRef = React.useRef();
  if (lottieRef.current) {
    lottieRef.current.play();
  };
  return <LottieView ref={lottieRef} source={require("./lottie.json")} speed={1} loop={false} />;
};

const InactiveLottie = props => {
  const lottieRef = React.useRef();
  if (lottieRef.current) {
    lottieRef.current.play();
  };
  return <LottieView ref={lottieRef} source={require("./lottie.json")} speed={-1} loop={false} />;
};

const tabIcons= {
  "Home": ({ focused }) => (focused ? <ActiveLottie/> : <InactiveLottie/>),  
  "Settings": ({ focused }) => <SettingsIcon focused={focused} />,  
  "Profile": ({ focused }) => <ProfileIcon focused={focused} />,  
}

const TabNavigator = createBottomTabNavigator({
  Home: HomeScreen,
  Settings: SettingsScreen,
  Profile: ProfileScreen,
}, { defaultNavigationOptions: ({ navigation }) => ({
  tabBarIcon: tabIcons[navigation.state.routeName]
  })
});

However, the active -> inactive tab animation for say tab A was playing when I was switching between tabs B and C, and I found out that although CrossFadeIcon renders both active and inactive tab icons with a different opacity, the Lottie view only accepts opacity as part of its own style and is not affected by its parent opacity.

This PR exposes the opacity applied by CrossFadeIcon to each tab icon child to fine-tune rendering logic on the client side.

Test plan

From the code above, change the behaviour of the Lottie components:

const ActiveLottie = props => {
  const lottieRef = React.useRef();
  React.useEffect(() => {
    if (props.currentOpacity === 1 && lottie.current) {
      lottie.current.play();
    }
  }, [currentOpacity]);
  return <LottieView ref={lottieRef} source={require("./lottie.json")} speed={1} loop={false} />;
};

const InactiveLottie = props => {
  const lottieRef = React.useRef();
  React.useEffect(() => {
    if (props.currentOpacity === 1 && lottie.current) {
      lottie.current.play();
    }
  }, [currentOpacity]);
  return <LottieView ref={lottieRef} source={require("./lottie.json")} speed={-1} loop={false} />;
};

@yassinecc yassinecc marked this pull request as ready for review November 17, 2019 20:52
@yassinecc
Copy link
Author

@satya164 @osdnk 🙏

@yassinecc
Copy link
Author

yassinecc commented Dec 10, 2019

Maybe @ahmedu007?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant