ReactNative

在expo的项目下:

import {useState} from “react”


//引进需要用的组件:

import {

  StatusBar,

  StyleSheet,

  Text,

  View,

  Image,

  ImageBackground,

  TextInput,

  ScrollView,

  Button,

  TouchableOpacity,

} from "react-native";



//native中的布局元素默认就是弹性盒
//不需要再去设置display:flex
//弹性盒的主轴方向和web端是相反的,是纵向的
//view不能加onPress事件的

 

第一次课
 

export default function App() {
  return (
    <View style={styles.container}>
      {/* 方法一 */}
    {/* <View style={styles.container}> */}
     {/* 点击事件,输出在终端 */}

      <Text onPress={() => {console.log('123')}} style={styles.textColor}>康康同学,你好啊!</Text>
      <Text onPress={() => {console.log('点击了')}} >今天   天气好晴朗</Text>
      {/* Text不能继承外层View字体样式的,能够继承父级Text组件样式 */}
      {/* Text可以加事件 */}
      <Text onPress={() => {console.log('点击了')}} >普通文本<Text>节点</Text></Text>
      <StatusBar backgroundColor="purple"/>
    </View>
  );
}
对应的样式代码:
container: {
    // 第一次课
    // 方法二:可以注释掉样式
    // flex: 1,
    backgroundColor: 'pink',
    height: 200,
    // 注意大写问题
    alignItems: 'center',
    justifyContent: 'center',
  },
  textColor: {
    color: 'yellow',
    fontSize: 40,

  },

第二次课:

// import { StatusBar } from 'expo-status-bar';
import { useState } from "react";
// 在这里引进需要用的组件
import {
  StatusBar,
  StyleSheet,
  Text,
  View,
  Image,
  ImageBackground,
  TextInput,
  ScrollView,
  Button,
  TouchableOpacity,
} from "react-native";

// native中的布局元素默认就是弹性盒
// 不需要再去设置display:flex
// 弹性盒的主轴方向和web端是相反的,纵向
// View不能加onPress事件的
export default function App() {
  const [value, setValue] = useState("");
  return (
    // <View style={styles.container}>
    <ScrollView>
      <TouchableOpacity
        style={{
          backgroundColor: "red",
          height: 100,
          width: 200,
          justifyContent: "center",
          alignItems: "center",
          borderRadius: 50,
        }}
        onPress={() => {
        }}
      ></TouchableOpacity>
      {/* <Button style={{ width: 100, height: 100, backgroundColor: "red" }}></Button> */}

      {/* <Text>{value}</Text>
      <TextInput
        value={value}
        onChangeText={(text) => setValue(text)}
        style={{
          width: 300,
          height: 30,
          borderColor: "red",
          borderWidth: 1,
          borderRadius: 10,
        }}
      ></TextInput> */}

      {/* <Image
      // resizeMode:cover:覆盖;center:居中;repeat:平铺很多个
        style={{ width: 100, height: 100, resizeMode:"center",borderColor: "blue", borderWidth: 1 }}
        source={require("./assets/favicon.png")}
        // 引入网络图片之前需要先设置大小
      />
      <Image
        style={{ width: 100, height: 100, resizeMode:"contain",borderColor: "blue", borderWidth: 1 }}
        source={require("./assets/icon.png")}
        // 引入网络图片之前需要先设置大小
      />
      <Image
      // 左右上下有空白
        resizeMode="contain"
        style={{ width: 200, height: 100, borderColor: "red", borderWidth: 1, position:"absolute" }}
        // 后缀为svg的可能出不来效果
        source={{uri: "https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png"}}
      /> */}

      {/* 布局元素设置了display:flex,position:relative */}
      {/* <Image
        style={{ width: 100, height: 100, position:"absolute" }}
        source={require("./assets/icon.png")}
        // 引入网络图片之前需要先设置大小
      /> 
       <Text>hello world</Text>
      */}

      {/* 文本是以背景图左上角为起始点开始的 */}
      {/* <ImageBackground
        source={require("./assets/icon.png")}
        style={{ width: 200, height: 100 }}
      >
        <Text>hello world</Text>
      </ImageBackground> */}
      {/* 
      <TextInput
        style={{
          borderWidth: 1,
          borderColor: "red",
          width: 300,
          height: 100,
          borderRadius: 10,
          alignSelf: "center",
          margin: 20,
          paddingHorizontal: 20,
        }}
      ></TextInput> */}
      {/* </View> */}
    </ScrollView>
  );
}
// 第一次课
// export default function App() {
//   return (
//     <View style={styles.container}>
//       {/* 方法一 */}
//     {/* <View style={styles.container}> */}
//      {/* 点击事件,输出在终端 */}

//       <Text onPress={() => {console.log('123')}} style={styles.textColor}>康康同学,你好啊!</Text>
//       <Text onPress={() => {console.log('点击了')}} >今天   天气好晴朗</Text>
//       {/* Text不能继承外层View字体样式的,能够继承父级Text组件样式 */}
//       {/* Text可以加事件 */}
//       <Text onPress={() => {console.log('点击了')}} >普通文本<Text>节点</Text></Text>
//       <StatusBar backgroundColor="purple"/>
//     </View>
//   );
// }

const styles = StyleSheet.create({
  // container: {
  //   // 第一次课
  //   // 方法二:可以注释掉样式
  //   // flex: 1,
  //   backgroundColor: 'pink',
  //   height: 200,
  //   // 注意大写问题
  //   alignItems: 'center',
  //   justifyContent: 'center',
  // },
  // textColor: {
  //   color: 'yellow',
  //   fontSize: 40,

  // },
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    justifyContent: "center",
    height: 200,
  },
});

相关推荐

  1. ReactNative

    2024-03-16 16:22:01       17 阅读
  2. <span style='color:red;'>react</span>

    react

    2024-03-16 16:22:01      37 阅读
  3. React

    2024-03-16 16:22:01       38 阅读
  4. React

    2024-03-16 16:22:01       15 阅读
  5. React

    2024-03-16 16:22:01       12 阅读
  6. ReactReact native

    2024-03-16 16:22:01       32 阅读
  7. React——关于react概述

    2024-03-16 16:22:01       24 阅读
  8. ReactReact响应事件

    2024-03-16 16:22:01       18 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-16 16:22:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-16 16:22:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-16 16:22:01       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-16 16:22:01       20 阅读

热门阅读

  1. qt QtMultimedia 报错

    2024-03-16 16:22:01       21 阅读
  2. P8752 [蓝桥杯 2021 省 B2] 特殊年份 Python

    2024-03-16 16:22:01       19 阅读
  3. 乐观锁与悲观锁

    2024-03-16 16:22:01       20 阅读
  4. Flink 简述

    2024-03-16 16:22:01       19 阅读
  5. python adb脚本

    2024-03-16 16:22:01       20 阅读
  6. 交叉编译代码

    2024-03-16 16:22:01       20 阅读
  7. ChatGPT升级版:如何借助ChatGPT高效撰写学术论文

    2024-03-16 16:22:01       24 阅读
  8. windows各个版本安装SSH

    2024-03-16 16:22:01       23 阅读
  9. CMake官方教程8--自定义命令和生成文件

    2024-03-16 16:22:01       19 阅读
  10. C#面:throw 和throw ex 的区别

    2024-03-16 16:22:01       18 阅读