rntpc_react-native-material-textfield:基于 React Native 的 Material 风格文本输入框项目

基于 react-native-material-textfield 的 OpenHarmony 适配版,Material Design 文本输入框组件(浮动标签)

Branch3Tags5
FilesLast commitLast update
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
6 months ago
6 months ago
4 days ago
4 days ago
7 years ago
6 years ago
6 years ago
6 years ago

Template version: v0.4.2

react-native-material-textfield

English | 简体中文

This project is based on react-native-material-textfield.

This third-party library has been migrated to AtomGit and is now available for direct download from npm, the new package name is: @react-native-ohos/react-native-material-textfield. The version correspondence details are as follows:

Third-Party Library Name Version (npm Address) Release Information Supported RN Version Autolink Compile API Version Community Baseline Version Source Code Address
@react-native-ohos/react-native-material-textfield ~ 0.17.0 AtomGit Releases 0.77.* /0.82.* No API12+ 0.16.1 br_rnoh0.77
@react-native-ohos/react-native-material-textfield ~ 0.16.1 AtomGit Releases 0.72.* No API12+ 0.16.1 br_rnoh0.72
@react-native-oh-tpl/react-native-material-textfield <= 0.16.1-0.0.4@deprecated Github Releases(deprecated) 0.72.* No API12+ 0.16.1 sig

Introduction

react-native-material-textfield is a high-quality, cross-platform text input component library designed specifically for React Native apps.

Installation

Run the following command in your project directory:

npm

npm install @react-native-ohos/react-native-material-textfield
npm install deprecated-react-native-prop-types

yarn

yarn add @react-native-ohos/react-native-material-textfield
yarn add deprecated-react-native-prop-types

Constraints

Compatibility

This document is verified based on the following versions:

  1. RNOH: 0.77.18; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.868; ROM: 6.0.0.112;
  2. RNOH: 0.82.22; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.878; ROM: 6.0.0.130;

Example

The following code demonstrates a basic usage scenario of this library:

The import library name remains unchanged during use.


import React, {useState} from 'react';
import {  StyleSheet,SafeAreaView,Platform,ScrollView,View,Button} from 'react-native';
import {
  TextField,
} from 'react-native-material-textfield';


let defaults = {
  firstname: 'Eddard',
  lastname: 'Stark'
};


export default function TextfieldDemo() {
  const [errors, setErrors] = useState({});
  const firstnameRef  = React.createRef();
  const lastnameRef  = React.createRef();
  const emailRef = React.createRef();
  const passwordRef = React.createRef();

  const onSubmit = () => {
    let errors = {};
    ['firstname', 'lastname', 'email', 'password']
    .forEach((name) => {
        const ref = name === 'firstname' ? firstnameRef :  
                    name === 'lastname' ? lastnameRef :
                    name === 'email' ? emailRef : 
                    passwordRef;       
        let value = ref.current ? ref.current.value() : ''; 
        if(!value) {
          errors[name] = 'Should not be empty';
        } else {
          if('password' === name && value.length < 6) {
            errors[name] = 'Too short';
          }
        }
    });
    setErrors(errors)
  }

  return (
    <SafeAreaView style={styles.safeContainer}>
        <ScrollView
            style={styles.scroll}
            contentContainerStyle={styles.contentContainer}
            keyboardShouldPersistTaps='handled'
          >
          <View style={styles.container}>
              <TextField
                ref={firstnameRef}
                value={defaults.firstname}
                autoCorrect={false}
                enablesReturnKeyAutomatically={true}
                returnKeyType='next'
                label='First Name'
                error={errors.firstname}
              />

             <TextField
                ref={lastnameRef}
                value={defaults.lastname}
                autoCorrect={false}
                enablesReturnKeyAutomatically={true}      
                returnKeyType='next'
                label='Last Name'
                error={errors.lastname}
              />  

              <TextField
                ref={emailRef}
                keyboardType='email-address'
                autoCapitalize='none'
                autoCorrect={false}
                enablesReturnKeyAutomatically={true}
                returnKeyType='next'
                label='Email Address'
                error={errors.email}
              />

              <TextField
                ref={passwordRef}
                autoCapitalize='none'
                autoCorrect={false}
                enablesReturnKeyAutomatically={true}
                returnKeyType='done'
                label='Password'
                title='Choose wisely'
                maxLength={30}
                secureTextEntry={true}
                characterRestriction={20}
                error={errors.password}
              />

             <Button title='running' color='#841584' onPress={onSubmit}></Button>
              
          </View>
        </ScrollView>

    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  safeContainer: {
    flex: 1,
    backgroundColor: '#FFFFFF',
  },
  scroll: {
    backgroundColor: 'transparent',
  },

  container: {
    margin: 8,
    marginTop: Platform.select({ harmony:8,ios: 8,android: 32 }),
    flex: 1,
  },

  contentContainer: {
    padding: 8,
  }
});

Available APIs

The "Platform" column indicates the platforms supported by the original third-party library.

If the value of "OpenHarmony Platform Support" is "Yes", it means that the OpenHarmony platform supports this property; "No" means the opposite; "Partially" means some capabilities of this property are supported. The usage method is the same on different platforms and the effect is the same as that of iOS or Android.

Properties

Name Parameter Type Default Value Required Platform OpenHarmony Platform Support Description
textColor String rgba(0, 0, 0, .87) No iOS/Android Yes Text input color
fontSize Number 16 No iOS/Android Yes Text input font size
labelFontSize Number 12 No iOS/Android Yes Text field label font size
lineWidth Number 0.5 No iOS/Android Yes Text field underline width
activeLineWidth Number 2 No iOS/Android Yes Text field active underline width
disabledLineWidth Number 1 No iOS/Android Yes Text field disabled underline width
tintColor String rgb(0, 145, 234) No iOS/Android Yes Text field accent color (cursor and active state)
baseColor String rgba(0, 0, 0, .38) No iOS/Android Yes Text field base color (default underline color)
label String - No iOS/Android Yes Text field label text
title String - No iOS/Android Yes Text field helper text
prefix String - No iOS/Android Yes Text field prefix text
suffix String - No iOS/Android Yes Text field suffix text (unit or fixed trailing content)
error String - No iOS/Android Yes Text field error text
errorColor String rgb(213, 0, 0) No iOS/Android Yes Text field color for errored state
lineType String solid No iOS/Android Yes Text field line type (solid, dotted, etc.)
disabledLineType String dotted No iOS/Android Yes Text field line type in disabled state
animationDuration Number 225 No iOS/Android Yes Text field animation duration in ms
characterRestriction Number - No iOS/Android Yes Text field soft limit for character counter
disabled Boolean false No iOS/Android Yes Text field availability
editable Boolean true No iOS/Android Yes Whether text field content can be edited
multiline Boolean false No iOS/Android Yes Whether the text field supports multiline input
contentInset Object { top: 16, label: 4, input: 8, left: 0, right: 0 } No iOS/Android Yes Layout configuration object for content insets
labelOffset Object { x0: 0, y0: 0, x1: 0, y1: 0 } No iOS/Android Yes Label position adjustment
inputContainerStyle Object - No iOS/Android Yes Style for input container view
containerStyle Object - No iOS/Android Yes Style for container view
labelTextStyle Object - No iOS/Android Yes Style for label inner Text component
titleTextStyle Object - No iOS/Android Yes Style for title inner Text component
affixTextStyle Object - No iOS/Android Yes Style for affix inner Text component
formatText Function - No iOS/Android Yes Input mask callback
renderLeftAccessory Function - No iOS/Android Yes Render left input accessory view
renderRightAccessory Function - No iOS/Android Yes Render right input accessory view
onChangeText Function - No iOS/Android Yes Change text callback
onFocus Function - No iOS/Android Yes Focus callback
onBlur Function - No iOS/Android Yes Blur callback

API(TextField)

Name Type Parameter Type Return Value Required Platform OpenHarmony Platform Support Description
focus function / / No iOS/Android Yes Acquire focus
blur function / / No iOS/Android Yes Release focus
clear function / / No iOS/Android Yes Clear text field
value function / String No iOS/Android Yes Get current value
isFocused function / Boolean No iOS/Android Yes Get current focus state
isErrored function / Boolean No iOS/Android Yes Get current error state
isRestricted function / Boolean No iOS/Android Yes Get current restriction state
isDefaultVisible function / Boolean No iOS/Android Yes Get default value visibility
isPlaceholderVisible function / Boolean No iOS/Android Yes Get placeholder visibility
setValue function String / No iOS/Android Yes Set current value

Known Issues

None

Other

None

Directory Structure

/rntpc_react-native-material-textfield   # Project root directory
├── src                                  # RN library source
│   └── components
│       ├── affix                        # Prefix / suffix component
│       │   ├── index.js
│       │   └── styles.js
│       ├── counter                      # Character counter component
│       │   ├── index.js
│       │   └── styles.js
│       ├── field                        # TextField core component
│       │   ├── index.js
│       │   └── styles.js
│       ├── field-filled                 # FilledTextField component
│       │   ├── index.js
│       │   └── styles.js
│       ├── field-outlined               # OutlinedTextField component
│       │   └── index.js
│       ├── helper                       # Helper text component
│       │   ├── index.js
│       │   └── styles.js
│       ├── label                        # Floating label component
│       │   ├── index.js
│       │   └── styles.js
│       ├── line                         # Underline component
│       │   ├── index.js
│       │   └── styles.js
│       └── outline                      # Outline border component
│           ├── index.js
│           └── styles.js
├── example                              # Example project
│   ├── src
│   │   └── TextFieldDemo.tsx            # Demo page
│   ├── harmony                          # OpenHarmony example project
│   │   ├── AppScope                     # App-level configuration
│   │   └── entry                        # OpenHarmony entry module
│   │       └── src/main
│   │           ├── ets
│   │           │   ├── entryability/EntryAbility.ets   # App entry
│   │           │   ├── pages/Index.ets                 # Demo home page
│   │           │   └── RNPackagesFactory.ets           # RN Package factory
│   │           ├── cpp
│   │           │   └── PackageProvider.cpp             # C++ Package entry
│   │           └── resources            # Resource files
│   └── index.js                         # Example entry
├── index.js                             # Library entry (exports TextField / FilledTextField / OutlinedTextField)
├── package.json
├── README.md                            # Chinese installation and usage guide
└── README_en.md                         # English installation and usage guide

How to Contribute

If you find any problem when using react-native-material-textfield, submit an Issue or a PR.

License

This project is based on The BSD 3-Clause License (BSD-3-Clause). Feel free to enjoy and participate in open source.

Introduction

基于 react-native-material-textfield 的 OpenHarmony 适配版,Material Design 文本输入框组件(浮动标签)

Customize your domain