Author: saqibkhan

  • How do you style your React Native component?

    Every React Native component like View, Text, Image etc… accepts a style prop which is an object of CSS rules. The only difference between CSS rules and CSS object used in React Native is key in CSS object has CSS rules in camelCase, for example, CSS rule background-colour will become backgroundColour in React Native. There are few restrictions over values of some CSS rules. But still, available CSS rules are enough to style a mobile app UI beautifully. React Native supports CSS flexbox to build UI layouts. We style our mobile screen like below snippet:

    const styles = StyleSheet.create({
       container: {
           flexDirection: 'row',
           borderRadius: 5,
           borderWidth: 1,
           borderColor: '#1a91b8',
           padding: 5,
           backgroundColor: '#eaf7fd'
       },
       text: {
           color: '#015169',
           fontWeight: 'bold',
           fontSize: 20,
           padding: 15
       }
    });
    Then we can use these style with View component like below:
    <View style={styles.container}></View>

    Stylesheet object is provided by React native library which has the method “create”. It takes an argument of type object and this object is the collection of CSS rules. As you can see in the above example, font-size CSS property in the web becomes font size in React native and flex-direction becomes flexDirection. I hope you got the idea about styling in React native application development. You can find the complete code on https://gist.github.com/PavanKu/98f92103af84faaf540aa348cf1a1126

  • Why do you need to install watchman software when setting up a development environment for React Native on MacOS?

    Introduction: Watchman is an open-source project developed by Facebook that monitors files and tracks changes. 

    FunctionalityIt can trigger actions based on file changes. 

    Hot Reloading in React Native: 

    • Watchman powers the hot reloading feature in React Native. 
    • Hot reloading allows developers to see changes immediately without recompiling the entire project. 
    • This feature speeds up development compared to traditional native mobile application development, which requires manual recompilation. 

    Automation: When a developer makes changes in a React Native project file, Watchman detects the changes and triggers an automatic build, reflecting updates without manual intervention. 

    Developer Benefits: The hot reloading feature makes React Native a developer-friendly framework, accelerating the development process. 

    Setup: Installation of Watchman is included in the React Native environment setup instructions. 

  • How do you start the React Native app development?

    Starting a project from scratch is always a little bit harder that is why there are some tooling available which we can use to bootstrap a React Native project.

    • Using react-native-cli (https://www.npmjs.com/package/react-native-cli)
      • react-native-cli created a pure react native application as it doesn’t hide any piece of code in the generated project. You can see ios and android folder in a directory structure. Although, you don’t need to modify anything inside generated ios and android folder, They are required to run React native application successfully on the device.
    • Using expo-cli (https://www.npmjs.com/package/expo-cli)
      • Expo-Cli is a third party tooling which provides base files and easy setup steps to start React Native app development. It also provides barcode based steps to share the app with other team members. The downside of bootstrapping React native app with expo cli is the size of the basic app is considerably big as expo cli includes few expo based libraries with the app.
  • Smart Task Prioritization

    Help users prioritize their tasks more effectively using algorithms.

    Implementing Smart Task Prioritization

    1. Define Criteria for Prioritization:

    Identify key factors, such as deadlines, importance, and user history.

    1. Create a Scoring System:

    Assign scores to tasks based on their criteria.

    javascriptCopy codeconst prioritizeTasks = (tasks) => {
      return tasks.sort((a, b) => {
    
    const scoreA = calculateScore(a);
    const scoreB = calculateScore(b);
    return scoreB - scoreA; // Higher score first
    }); }; const calculateScore = (task) => { // Example: score based on deadline proximity and importance return task.importance * (1 / (task.deadline - Date.now())); };
    1. Display Prioritized Tasks:

    Show users their tasks in order of priority.

    Step 2: Integration with Fitness Tracking

    Encourage users to maintain a balance between productivity and wellness by integrating with fitness apps.

    Implementing Fitness Tracking Integration

    1. Choose Fitness APIs:

    Consider APIs from Fitbit, Apple Health, or Google Fit.

    1. Authenticate Users:

    Implement OAuth for users to connect their fitness accounts.

    javascriptCopy codeconst connectFitnessAccount = async () => {
      // OAuth flow to connect fitness account
    };
    
    1. Display Fitness Data:

    Show users their fitness data alongside task completion metrics.

    javascriptCopy codeconst [steps, setSteps] = useState(0);
    
    // Fetch and display fitness data
    
    1. Set Fitness-Related Goals:

    Allow users to set productivity goals that incorporate physical activity (e.g., “Complete 5 tasks and walk 10,000 steps”).

    Step 3: Dynamic Task Templates

    Allow users to create and reuse templates for common tasks or projects.

    Implementing Dynamic Task Templates

    1. Template Creation:

    Create a UI for users to define a task template (e.g., checklists, due dates).

    javascriptCopy codeconst [taskTemplate, setTaskTemplate] = useState({ name: '', checklist: [] });
    
    1. Save and Load Templates:

    Store templates in the database or AsyncStorage.

    javascriptCopy codeconst saveTemplate = async () => {
      // Logic to save the template
    };
    
    1. Use Templates for New Tasks:

    Enable users to select a template when creating a new task.

    Step 4: Video Tutorials and Onboarding

    Enhance user experience by providing tutorials and a smooth onboarding process.

    Implementing Video Tutorials

    1. Create Onboarding Screens:

    Design onboarding screens that introduce the app’s features.

    1. Incorporate Video Content:

    Use react-native-video to embed tutorial videos within the app.

    javascriptCopy codeimport Video from 'react-native-video';
    
    const TutorialVideo = () => (
      <Video source={require('./path/to/video.mp4')} style={styles.video} />
    );
    
    1. Interactive Walkthroughs:

    Create interactive tutorials that guide users through the app’s functionalities.

    Step 5: Push Notifications for Deadlines

    Remind users of approaching deadlines to help them stay on track.

    Implementing Push Notifications

    1. Set Up Push Notifications:

    Use libraries like @react-native-firebase/messaging or react-native-push-notification.

    bashCopy codenpm install @react-native-firebase/messaging
    
    1. Schedule Notifications:

    Allow users to set notifications for task deadlines.

    javascriptCopy codeimport PushNotification from 'react-native-push-notification';
    
    const scheduleNotification = (task) => {
      PushNotification.localNotificationSchedule({
    
    message: Deadline approaching for: ${task.name},
    date: new Date(task.deadline),
    }); };
    1. Configure Notification Preferences:

    Let users customize how they receive notifications (e.g., sound, vibration).

  • What is state in the React component?

    State is another way apart from props by which we can modify a React component. React component’s state value changes in the life cycle of component, unlike props. We should not directly change state value of react component. React framework gives the setState method by which state of a component should be changed.

    React framework
    import React from 'react';
    import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
    
    class Counter extends React.Component {
        state = { count: 0 };
        increment = () => this.setState({count: this.state.count + 1});
        decrement = () => this.setState({count: this.state.count - 1});
        render() {
            return (
                <View style={styles.container}>
                    <TouchableOpacity onPress={this.decrement}>
                        <Text style={styles.text}>-</Text>
                    </TouchableOpacity>
                    <Text style={styles.text}>{this.state.count}</Text>
                    <TouchableOpacity onPress={this.increment}>
                        <Text style={styles.text}>+</Text>
                    </TouchableOpacity>
                </View>
            );
        }
    };
    const styles = StyleSheet.create({
        container: {
            flexDirection: 'row',
            borderRadius: 5,
            borderWidth: 1,
            borderColor: '#1a91b8',
            padding: 5,
            backgroundColor: '#eaf7fd'
        },
        text: {
            color: '#015169',
            fontWeight: 'bold',
            fontSize: 20,
            padding: 15
        }
    });
    export default Counter;

    Above code is an implementation of a counter component. This component has a state count whose value is changed by clicking on the plus (+) and minus (-) button. As the state count of this component is changing the number displayed on UI is also changing. Whenever we create any component in React, first we divide the screen in the component then decide what state a component should have. The beauty of this component is that it is an independent component and can be used anywhere in the application. That is how we make several fully functional component in React to build the complete application.

  • What are props in React Component?

    Props are parameters which are used to customise a component at the time of creation and on re-render. Props are like arguments passed to a React component. For example, Image is a very basic component provided by React Native library to display an image. It accepts a prop called source which is used to control what image it shows. By passing different values of props, one component can show different UI and different functionality. So we can say that props help use and reuse the same component at different places. Props are set by the parent component and remain fixed for an entire lifecycle of a component.

    React Component
    import React from 'react';
    import { StyleSheet, Text, View, Image } from 'react-native';
    import Counter from './components/Counter';
    import Greeting from "./components/Greeting2";
    import SimpleTextInput from './components/SimpleTextInput';
    import SimpleButton from './components/SimpleButton';
    import LoginForm from './components/LoginForm';
    import PictureList from './components/PictureList';
    
    export default class App extends React.Component {
      render() {
        const pictureData = {
          uri: 'https://picsum.photos/300/300'
        };
        return (
          <View style={styles.container}>
            <PictureList />
          </View>
        );
      }
    }
    
    const styles = StyleSheet.create({
      container: {
        flex: 1,
        backgroundColor: '#f5fcff',
        alignItems: 'center',
        justifyContent: 'center',
      },
      image: {
        margin: 5,
        borderRadius: 5,
        width: 300,
        height: 300
      }
    });
  • What is component driven development and what are the benefits of using component driven development?

    Long time back, web developer realises that there are few elements which are frequently used in web development like drop down and different type of button. The developer started making CSS frameworks which provide already developed components. Bootstrap was first very popular CSS framework which helped web developer to build user experience very quickly. React also follows the same approach in web development. 

    Component driven development is a methodology where we break the complete UI design into several small reusable components and develop them independently. Then the complete UI is built by composing these small components. This methodology helps us write UI code in a modular way. UI development will be faster as we will be reusing components at multiple places. Less code also results in less effort in maintaining the code and also less number of bugs. So we can say that component driven development was already there in web development but React JS made it very popular in the developer community. New frameworks like Angular4+ are also following the same methodology to develop the web application.

  • Customizable Reminders

    Allow users to personalize their reminders with various sounds and repeat intervals.

    Implementing Customizable Reminders

    1. Sound Selection:

    Provide users with a list of notification sounds they can choose from.

    javascriptCopy codeconst sounds = ['Default', 'Chime', 'Alert', 'Bell'];
    const [selectedSound, setSelectedSound] = useState(sounds[0]);
    
    1. Repeat Intervals:

    Let users select how often they want reminders to repeat.

    javascriptCopy codeconst repeatOptions = ['None', 'Daily', 'Weekly', 'Monthly'];
    const [repeatInterval, setRepeatInterval] = useState(repeatOptions[0]);
    
    1. Schedule Reminders:

    When creating a task, allow users to schedule the reminder with the selected sound and repeat option.

    javascriptCopy codeconst scheduleReminder = (task) => {
      // Use a notification library to schedule the reminder
    };
    

    Step 2: Offline Functionality

    Enable users to manage their tasks even when they’re offline.

    Implementing Offline Functionality

    1. Use AsyncStorage:

    Store tasks in AsyncStorage for offline access.

    javascriptCopy codeconst saveTasksOffline = async (tasks) => {
      await AsyncStorage.setItem('tasks', JSON.stringify(tasks));
    };
    
    1. Sync on Reconnect:

    When the user reconnects to the internet, sync local changes with the server.

    javascriptCopy codeconst syncTasks = async () => {
      const localTasks = await AsyncStorage.getItem('tasks');
      // Sync with server
    };
    
    1. Notify Users:

    Inform users when they are offline and any changes will be saved locally.

    Step 3: Integrate Third-Party Services

    Connect your app with popular productivity tools to enhance functionality.

    Implementing Third-Party Integrations

    1. Use APIs:

    Identify APIs for services like Slack, Trello, or Asana.

    1. Authentication:

    Implement OAuth for user authentication with third-party services.

    javascriptCopy codeconst authenticateWithService = async () => {
      // Use OAuth flow to authenticate
    };
    
    1. Task Synchronization:

    Allow users to import/export tasks between your app and third-party services.

    javascriptCopy codeconst importTasksFromTrello = async () => {
      // Fetch tasks from Trello API
    };
    

    Step 4: Social Features

    Create a social component where users can connect and interact with friends.

    Implementing Social Features

    1. Friend Connections:

    Allow users to send and receive friend requests.

    javascriptCopy codeconst [friends, setFriends] = useState([]);
    const sendFriendRequest = (friendId) => {
      // Logic to send friend request
    };
    
    1. Task Sharing:

    Let users share specific tasks with friends.

    javascriptCopy codeconst shareTaskWithFriend = (taskId, friendId) => {
      // Logic to share task
    };
    
    1. Progress Tracking:

    Enable users to view friends’ progress on shared tasks or goals.

    Step 5: Personalized Dashboard

    Create a customizable dashboard where users can prioritize tasks.

    Implementing a Personalized Dashboard

    1. Drag and Drop Functionality:

    Allow users to reorder tasks on their dashboard.

    javascriptCopy codeimport { TouchableOpacity } from 'react-native';
    
    const reorderTasks = (newOrder) => {
      setTasks(newOrder);
    };
    
    1. Widgets:

    Enable users to add or remove widgets, such as upcoming deadlines, progress bars, or priority tasks.

    1. Visual Customization:

    Allow users to change the layout or color scheme of their dashboard.

  • What is JSX?

    JSX is a system used for embedding XML in Javascript. You can say that JSX is a templating language for writing HTML/XML tags with Javascript. With the help of JSX, HTML/XML can be written inside Javascript file. JSX enables conditional rendering of React components. React includes building step which converts JSX into Javascript code which is ultimately executed by browser in case of a web app or react Native in case of React Native. JSX is added to improve the developer experience. ReactJS provides few APIs which make the HTML structure in a browser. Those APIs were a little cumbersome to frequently used. That is why React JS introduced JSX and added a tooling step to convert JSX into platform understandable code. With the help of JSX, we can execute javascript to build HTML tags very easily.  Here is an example of a JSX code:

    <View style={styles.container}>
    <TouchableOpacity onPress={this.decrement}>
    <Text style={styles.text}>-</Text>
    </TouchableOpacity>
    <Text style={styles.text}>{this.state.count}</Text>
    <TouchableOpacity onPress={this.increment}>
    <Text style={styles.text}>+</Text>
    </TouchableOpacity>
    </View>

    Above JSX code is creating one View component which contains two TouchableOpacity component as its child element. We are accessing Javascript variable in Text component with curly brace.

  • How mobile app development with React Native is different than web app development with ReactJS

    I’m listing down set of categories that shows how mobile app development is different than web app development using react —  

    Origin and Architecture: Both developed and open-sourced by Facebook Inc., React Native follows ReactJS’s basic architecture and promotes a component-based approach to building mobile screens. They share similar lifecycle methods.

    UI Components: 

    • ReactJS: Uses HTML tags like div, span, etc. 
    • React Native: Uses components like View and Text from the React Native library. 

    Platform and Browser Features: 

    • ReactJS: Built for web applications, allowing access to browser features like the window object and local storage. 
    • React Native: Built for native platforms, lacking access to browser-specific features. 

    GitHub Projects: ReactJS and React Native are separate open-source projects on GitHub. 

    Feature ImplementationNew component architecture features are first implemented in ReactJS and later added to React Native. 

    Development ToolsBoth frameworks have different tools for getting started with development. 

    Static Type Checking: 

    • React NativeComes with static type checking enabled by default. 
    • ReactJS: Requires additional steps to enable flow static type checking. 

    The above list of differentiation make clear how react and react native are works and different.