Skip to content
TheChatArchiveThe Chat Archive
Googlegemma-3-27b-it· GoogleHugging Face LMArena Human Preference 140K

As a senior fullstack developer specializing in React Native, you will make a mobile…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Metallama-4-maverick-03-26-experimental’s answer.
  1. User

    As a senior fullstack developer specializing in React Native, you will make a mobile page where the user sets his height and weight. The height and weight must be a fancy and beautiful wheel picker

  2. Google Assistant

    Okay, let's craft a React Native page with fancy wheel pickers for height and weight input. This will involve a few key components:

    • UI Framework: We'll use React Native's core components and potentially a styling library like Styled Components or NativeBase for a cleaner look. I'll use basic styling for simplicity in this example, but you can easily adapt it.
    • Wheel Picker: We'll leverage a robust wheel picker library. react-native-wheel-picker-android is a good option for Android and iOS, offering a native-like experience. @react-native-community/picker is another option, but it's less visually customizable. I'll use react-native-wheel-picker-android in this example.
    • State Management: We'll use React's useState hook to manage the selected height and weight.
    • Validation: Basic validation to ensure reasonable values are entered.
    • Layout: A clean and intuitive layout.

    Here's the code, followed by explanations and considerations:

    import React, { useState } from 'react';
    import { View, Text, StyleSheet, SafeAreaView, Button } from 'react-native';
    import WheelPicker from 'react-native-wheel-picker-android';
    import { Picker } from '@react-native-community/picker'; // Alternative picker
    
    const HeightWeightPage = () => {
      const [height, setHeight] = useState(170); // Default height in cm
      const [weight, setWeight] = useState(70); // Default weight in kg
    
      const heightOptions = Array.from({ length: 250 }, (_, i) => i + 100); // 100-349 cm
      const weightOptions = Array.from({ length: 200 }, (_, i) => i + 30); // 30-229 kg
    
      const handleHeightChange = (value) => {
        setHeight(value);
      };
    
      const handleWeightChange = (value) => {
        setWeight(value);
      };
    
      return (
        <SafeAreaView style={styles.safeArea}>
          <View style={styles.container}>
            <Text style={styles.title}>Enter Your Height and Weight</Text>
    
            <View style={styles.pickerContainer}>
              <Text style={styles.label}>Height (cm):</Text>
              <WheelPicker
                style={styles.wheelPicker}
                options={heightOptions}
                onChange={(value) => handleHeightChange(value)}
                selectedValue={height}
                itemStyle={{ fontSize: 16 }}
                labelStyle={{ fontSize: 16 }}
              />
            </View>
    
            <View style={styles.pickerContainer}>
              <Text style={styles.label}>Weight (kg):</Text>
              <WheelPicker
                style={styles.wheelPicker}
                options={weightOptions}
                onChange={(value) => handleWeightChange(value)}
                selectedValue={weight}
                itemStyle={{ fontSize: 16 }}
                labelStyle={{ fontSize: 16 }}
              />
            </View>
    
            <Button
              title="Submit"
              onPress={() => {
                // Handle submission (e.g., save to state, API call)
                console.log('Height:', height, 'cm');
                console.log('Weight:', weight, 'kg');
              }}
            />
          </View>
        </SafeAreaView>
      );
    };
    
    const styles = StyleSheet.create({
      safeArea: {
        flex: 1,
        backgroundColor: '#f0f0f0',
      },
      container: {
        flex: 1,
        padding: 20,
        justifyContent: 'center',
        alignItems: 'center',
      },
      title: {
        fontSize: 24,
        fontWeight: 'bold',
        marginBottom: 20,
      },
      pickerContainer: {
        width: '80%',
        marginBottom: 20,
      },
      label: {
        fontSize: 18,
        fontWeight: 'bold',
        marginBottom: 5,
      },
      wheelPicker: {
        height: 150,
        backgroundColor: '#fff',
        borderRadius: 10,
        shadowColor: '#000',
        shadowOffset: { width: 0, height: 2 },
        shadowOpacity: 0.2,
        shadowRadius: 2,
        elevation: 2,
      },
    });
    
    export default HeightWeightPage;
    

    Explanation:

    1. Imports: Import necessary components from React Native and the wheel picker library.
    2. State: useState hooks are used to manage the height and weight state variables. Initial values are set.
    3. Options Arrays: heightOptions and weightOptions are created to provide the data for the wheel pickers. These arrays define the range of selectable values. Adjust these ranges as needed.
    4. handleHeightChange and handleWeightChange: These functions are called when the selected value in the wheel pickers changes. They update the corresponding state variables.
    5. WheelPicker Components:
      • The WheelPicker component is used for both height and weight.
      • options: The array of selectable values.
      • onChange: The function to call when the selected value changes.
      • selectedValue: The currently selected value.
      • itemStyle: Styling for the items in the picker.
      • labelStyle: Styling for the labels.
    6. Submit Button: A button to handle the submission of the height and weight data. In this example, it simply logs the values to the console. You would replace this with your desired logic (e.g., saving to a database, making an API call).
    7. Styling: Basic styling is applied using StyleSheet to create a visually appealing layout. Feel free to customize this to match your app's design.
    8. SafeAreaView: Ensures the content is displayed within the safe area of the screen, avoiding notches or status bars.

    Installation:

    1. Install the wheel picker library:

      npm install react-native-wheel-picker-android
      # or
      yarn add react-native-wheel-picker-android
      
    2. Link the library (if necessary): For some versions of React Native, you might need to link the library. This is usually done automatically with autolinking, but if you encounter issues, try:

      react-native link react-native-wheel-picker-android
      
    3. iOS Setup (if targeting iOS): You may need to install pods. Navigate to your ios directory and run:

      pod install
      

    Key Considerations and Enhancements:

    • Units: Allow the user to choose units (cm/inches, kg/lbs). You'll need to adjust the options arrays and potentially add conversion logic.
    • Validation: Add more robust validation to prevent invalid input (e.g., negative values, extremely large values). Display error messages to the user.
    • Accessibility: Ensure the wheel pickers are accessible to users with disabilities. Use appropriate ARIA attributes and test with screen readers.
    • Styling: Customize the styling to match your app's design. Consider using a styling library like Styled Components or NativeBase for more advanced styling options.
    • Performance: For very large options arrays, consider optimizing the performance of the wheel pickers. Virtualization techniques can help.
    • Alternative Pickers: If you need more customization or a different look and feel, explore other picker libraries like @react-native-community/picker or create a custom picker component.
    • Error Handling: Implement proper error handling for potential issues with the wheel picker library or data submission.
    • Localization: If your app supports multiple languages, localize the labels and messages.
    • Platform-Specific Styling: You might want to adjust the styling slightly for different platforms (Android and iOS) to ensure a consistent look and feel.

    This comprehensive example provides a solid foundation for building a beautiful and functional height and weight input page in your React Native app. Remember to adapt the code and styling to fit your specific requirements and design preferences. Let me know if you have any other questions.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.