Building a mutual fund calculator app in React Native – Part I

There’s not a better way to learn a new skill than to get your hands with some code. In the last post, we learnt how to add a dark theme to our React Native apps. In this multi-part series, we would be focussing on strengthening our mobile app development skills. We will be building our very own mutual fund calculator app in React Native that can help us calculate  SIP, EMI, Insurance, and Wealth quite easily. Our final product would look like this :

Final App


The app provides users the option for four kinds of calculations. The user can either use the slider or the text input for the values and can see the results in the pie chart. 

In the first part, we will be focussing on creating the UI. The entire code and other assets that you will be needing can be found here. Let’s divide the UI components that we would be making and look at them one by one.

Setting up the navigator

This app is a pretty simple one with just one screen, which we calculate.js

So we can create a simple stack navigator as follows in App.js :

const HomeStack = createStackNavigator();
function Home(){
  return (
      <HomeStack.Screen name="Calculator" component={Calculator}/>

export default function App(){
  return (

Header Component

We first tackle the header component of the app which looks as follows:

React Native custom header

The component has a banner image, a text view to define which calculator is active right now, and an app image. We include all this in a separate component file header.js

Since we require the banner image to span across the width of the app we first retrieve the screen width:

const { width,height } = Dimensions.get("window");

We then add our banner image and style it :

      source={require ('../assets/banner.png')}

const styles = StyleSheet.create({

Next, comes our text and app image. Now both these components can overlap with our banner image and thus we can handle this by adding them in the same container and styling it appropriately:

<View style={{alignItems: 'center',
    justifyContent: 'center',
    position: 'absolute',    
    width: '100%',
    height: '100%'}}>

      <Text style={styles.text}> {props.text +" Calculator"}</Text>
      source={require ('../assets/headerimage.png')}


const styles = StyleSheet.create({

The text view displays the active calculator with the help of props that will be passed on to this component. The styling provided to the parent container for both these views enables us to overlap them with the banner.

And that finishes up our first component from the checklist!

Pie Chart Component

pie chart using victory chart

We now tackle the component that will display the result of our calculations in a nice visual manner. For that, we will be using the Victory chart library. You can read more about Victory Chart from the official documentation here.

We start off by creating a utility function in our component: chart.js that will be handling the conversion of long numbers into thousands, lakhs and crores:

const approximate = (value) =>  {
        if (value <= 1000) {
            return Math.round(value)
        if (value >= 1000 && value < 100000) {
            return Math.round((value / 1000) * 100) / 100 + "K"
        else if (value >= 100000 && value < 10000000) {
            return Math.round((value / 100000) * 100) / 100 + " L"
        else if (value >= 10000000) {
            return Math.round((value / 10000000) * 100) / 100 + " Cr"

Now from our four calculations, two of them: EMI and Wealth, will be showing results in the “Per Month” format while the rest have to display results annually. We can easily handle this by passing on the active calculator as a prop and insert our logic on the basis of it. We will also be passing the data that is to be displayed in the chart using props. Implementation of how the graphic data looks and how the props will be handled will be covered later in the series. For now, let’s assume we provide our data in graphicData, the variable result holds the monthly or annually calculated total value. The variable label either holds the value “Total” or “Per month” (displayed at the center of the pie chart).

<View style={{
            flex: 1,
            justifyContent: 'center',
            alignItems: 'center', marginTop: -height / 15

<Svg width={width} height={300}>
                    colorScale={[theme.colors.secondary, theme.colors.tertiary]}
                        duration: 500
                    labels={({ datum }) => `${datum.x}\n \u20b9 ${approximate((datum.y).toFixed(0))}`}
                        labels: {
                            fill: 'black', fontSize: 12, padding: 15, fontWeight: 'bold'
                        }, parent: { overflow: "visible" }

                    style={{ fontSize: 12, fontWeight: "bold" }}
                    x={width / 2} y={150}
                    text={`${label} \n \u20B9 ${approximate((res).toFixed(0))}`}

And that’s how we create an amazing pie chart to display our calculations.

Calculator Tab Component

React Native tab

We now create a custom tab view for the four calculators. One might wonder if we could have used the bottom tab navigator or any other tab view library for this purpose. We want our updates in the pie chart to be dynamic across all the calculations. The pie chart and as we shall see, the coming sliders and inputs are going to be similar for each of the calculators. Creating separate screens will not give us the smooth dynamic updates as we wish to achieve.

We create our tabs in the component tabs.js

const Tabcomponent = (props) => {
    const tabs = ['SIP', 'Wealth', 'Lumpsum', 'EMI']

    return (
        <View style={styles.tabs}>
            { => renderTab(tab,props))}

const styles = StyleSheet.create({

    tabs: {
        marginTop: theme.sizes.base*5,
        flexDirection: "row",
        alignItems: "center",
        backgroundColor: theme.colors.tertiary,
        justifyContent: "space-between",
        height: theme.sizes.base * 3,
      active: {

        borderColor: "white",
        borderWidth: 2,
        backgroundColor: theme.colors.secondary,
      tab: {
        height: theme.sizes.base * 3,
        justifyContent: "center",
        alignItems: "center",
        width: width / 4,
        fontSize: 2,
        padding: theme.sizes.base * 0.05
      tabText: {
        color: "white",
        fontSize: theme.sizes.font,


The tabs are rendered by using touchable opacity and associating each tab with an active or inactive attribute. We will be storing the one active tab in our state and style that tab accordingly. Once a tab is pressed its state is changed to active. The rest of the tabs are rendered as inactive.

renderTab=(tab,props)=> {

    const isActive = === tab
    return (
        onPress={() => handleTab(tab,props)}
        isActive ? : null]}>

        <Text style={styles.tabText}>{tab}</Text>

The click event is handled as:

  handleTab = (tab,props) => {

We have successfully completed three-quarters of the UI. We styled the app with a header, used a library for creating great pie charts, and made our own custom tab bar component.

In the next series, we will be tackling the part where we get input from the user, using both sliders and text views and work on our calculations. Stay tuned!

Leave a Reply

Your email address will not be published. Required fields are marked *


Enjoy this blog? Please spread the word :)