Skip to content

Commit

Permalink
update doc 《导航栏组件》
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyang committed Mar 14, 2024
1 parent fe6d024 commit cd2529c
Show file tree
Hide file tree
Showing 23 changed files with 420 additions and 15 deletions.
77 changes: 77 additions & 0 deletions content/posts/rn/base-components/BaseNavBar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { StyleSheet, Text, TouchableOpacity, View } from "react-native";
import React from "react";
import { getStatusBarHeight } from "app/utils/index";
import HBImage from "../image/HBImage";
import { px2dp } from "../../utils/ScreenUtils";
import { Actions } from "react-native-router-flux";

const BaseNavBar = ({ children, title, shouldHideBack, backClicked }) => {
return (
// 状态+导航栏 容器
<View style={styles.container}>
{/* 导航栏 */}
<View style={styles.navContainer}>
{/* left 返回按钮 */}
{shouldHideBack ? null : (
<TouchableOpacity
style={{ width: 36, zIndex: 1 }}
onPress={() => {
backClicked ? backClicked() : Actions.pop();
}}
>
<HBImage
source={require("app/img/navigationBar/icon-back-black.png")}
style={{
marginLeft: px2dp(12),
width: 21,
height: 21,
marginTop: px2dp(1.5),
}}
/>
</TouchableOpacity>
)}

{/* 标题 */}
{title && (
<View style={styles.titleContainer}>
<Text style={styles.title}>{title}</Text>
</View>
)}

{/* 其它内容 e.g.右侧按钮 */}
{children}
</View>
</View>
);
};

export default BaseNavBar;

const styles = StyleSheet.create({
container: {
width: "100%",
height: getStatusBarHeight() + 44,
backgroundColor: "#fff",
},

navContainer: {
width: "100%",
marginTop: getStatusBarHeight(),
height: 44,
backgroundColor: "#fff",
flexDirection: "row",
alignItems: "center",
},
titleContainer: {
position: "absolute",
width: "100%",
justifyContent: "center",
alignItems: "center",
},
title: {
fontSize: px2dp(18),
color: "#333",
textAlignVertical: "center",
lineHeight: 44,
},
});
50 changes: 50 additions & 0 deletions content/posts/rn/base-components/LeftUpBackButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from "react";
import HBImage from "app/components/image/HBImage";
import { TouchableOpacity, View } from "react-native";
import { px2dp } from "app/utils/ScreenUtils";
import { Actions } from "react-native-router-flux";
import * as indexUtil from "app/utils/index";

/**
* 返回按钮
* @param {*} props onPress,
* @returns
*/
const LeftUpBackButton = ({ onPress, iconType }) => {
return (
<TouchableOpacity
style={{
zIndex: 999,
position: "absolute",
top: indexUtil.getStatusBarHeight(),
width: px2dp(50),
height: 44,
justifyContent: "center",
left: 0,
}}
onPress={() => {
if (onPress) {
onPress();
} else {
Actions.pop();
}
}}
>
<HBImage
source={
iconType == "white"
? require("app/img/Status_bar_return.png")
: require("app/img/navigationBar/icon-back-black.png")
}
style={{
marginLeft: px2dp(12),
width: px2dp(11),
height: px2dp(19),
marginTop: px2dp(1.5),
}}
/>
</TouchableOpacity>
);
};

export default LeftUpBackButton;
85 changes: 83 additions & 2 deletions content/posts/rn/base-components/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default FeedList;
优点: 使用了高性能图片库FastImage,封装为 可配置图片加载失败后展示的占位error图


使用示例
### 使用示例
```javascript
// aliyun oss image format
// error image url: https://cdn.xxx.com/pic/illustrationstory/default/default_cover_720-1080.png?x-oss-process=image/resize,w_150/quality,q_85/format,webp
Expand Down Expand Up @@ -182,4 +182,85 @@ const getHeightFromSize = (size) => {
if (!(size?.width > 0) || !(size?.height > 0)) return 0;
return Math.min((imageSize * size.height) / size.width, maxImageHeight);
};
```
```
# 状态栏导航栏组件
源码:[BaseNavBar.js](./BaseNavBar.js)
优点:
* 带 返回按钮,点击返回上一页
* 带 title
* 支持自定义导航栏内子视图
* 使用时无需考虑状态栏适配了(内部处理了)
### 使用示例
* 最常规用法 [ `返回键` + `title` ]
使用场景:几乎所有页面
![normal](media/nav/nav_normal.png)
```javascript
import BaseNavBar from "app/components/navBar/base";
<BaseNavBar title={"书架筛选"} />
```
* 自定义导航栏内容用法
使用场景:导航栏需要特别自定义时
![custom](media/nav/nav_custom_child.png)
```javascript
import BaseNavBar from "app/components/navBar/base";
<BaseNavBar>
{/* 搜索栏 */}
<View style={styles.inputContainer}>
<TextInput
style={styles.textInput}
placeholder={placeholder || "输入搜索关键字"}
placeholderTextColor={"#999999"}
onChangeText={onChangeText}
value={keyword}
onSubmitEditing={_onClickSubmit}
keyboardType="web-search"
returnKeyType="search"
autoFocus={true}
/>
<TouchableOpacity style={styles.closeButton} onPress={clearInput}>
<Image
style={styles.closeButtonImage}
source={require("./images/close-gray.png")}
/>
</TouchableOpacity>
</View>
<TouchableOpacity style={styles.searchButton} onPress={_onClickSubmit}>
<Text style={{ fontSize: px2dp(16), color: "#666666" }}>搜索</Text>
</TouchableOpacity>
</BaseNavBar>
```
# 页面左上角的返回按钮组件
源码:[LeftUpBackButton.js](./LeftUpBackButton.js)
优点:
* 避开了状态栏
* 热区足够大
* 使用起来极简
使用场景:不需要导航栏 但需要返回按钮的页面,e.g. 一些全屏弹窗(图片查看器...)
### 使用示例
![custom](media/nav/back_button.png)
```javascript
import LeftUpBackButton from "app/components/LeftUpBackButton";
<LeftUpBackButton
//iconType="white"
//onPress={() => {
//dismiss alert
//}}
/>
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions content/posts/rn/readme/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ tags: [react-native]
* [基础组件封装](../base-components/)
* [瀑布流列表base组件](../base-components/#瀑布流列表base组件)
* [图片base组件](../base-components/#图片base组件)
* [...](../base-components/)

* [实现 模仿抖音、小红书 输入 ***`#标签`*** 高亮](../douyin-label-input/)

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion public/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<link>https://zyestin.github.io/zyestin/posts/rn/readme/</link>
<pubDate>Wed, 01 Nov 2023 12:00:11 +0800</pubDate>
<guid>https://zyestin.github.io/zyestin/posts/rn/readme/</guid>
<description>一些业务的最佳实践探索 基础组件封装&#xA;瀑布流列表base组件 图片base组件 实现 模仿抖音、小红书 输入 #标签 高亮&#xA;瀑布流列表&#xA;瀑布流最佳实践:双列均匀分布,高度计算&amp;amp;缓存 实现 瀑布流列表·自动滚动动画 实现 横向·瀑布流列表 实现 仿抖音/小红书 对贴图/贴字 进行拖拽、缩放、旋转等复杂手势&#xA;封装一个 易用的、远程字体动态下载&amp;amp;应用组件&#xA;封装一个 低耦合、易用的文本输入框弹窗&#xA;实现 差不多理想的极简RN弹窗&#xA;实践 列表Item精确曝光埋点 [todo]&#xA;实践 多tab多列表滑动吸顶效果 [todo]&#xA;实践 服务端下发自定义组件代码 前端接收&amp;amp;渲染[todo]&#xA;实践 拆包 [todo]&#xA;组件库 易用的应用远程字体的text组件库 - react-native-remote-font 其它(提效、工具&amp;hellip;) 探究 代码规范&#xA;React Native 编码提效 on VSCode&#xA;用脚手架 制作一个RN库 放npm(含踏坑记录)&#xA;贡献给react-native的第一个PR&#xA;React学习收获&#xA;学习《React Hooks 核心原理与实战》笔记 常用hooks依赖检查,从源头提醒避免奇葩bug &amp;hellip; npm 好用工具&#xA;patch-package 补丁工具使用 &amp;hellip; 从0到1用Jenkins实现对RN项目一键打包、发布</description>
<description>一些业务的最佳实践探索 基础组件封装&#xA;瀑布流列表base组件 图片base组件 &amp;hellip; 实现 模仿抖音、小红书 输入 #标签 高亮&#xA;瀑布流列表&#xA;瀑布流最佳实践:双列均匀分布,高度计算&amp;amp;缓存 实现 瀑布流列表·自动滚动动画 实现 横向·瀑布流列表 实现 仿抖音/小红书 对贴图/贴字 进行拖拽、缩放、旋转等复杂手势&#xA;封装一个 易用的、远程字体动态下载&amp;amp;应用组件&#xA;封装一个 低耦合、易用的文本输入框弹窗&#xA;实现 差不多理想的极简RN弹窗&#xA;实践 列表Item精确曝光埋点 [todo]&#xA;实践 多tab多列表滑动吸顶效果 [todo]&#xA;实践 服务端下发自定义组件代码 前端接收&amp;amp;渲染[todo]&#xA;实践 拆包 [todo]&#xA;组件库 易用的应用远程字体的text组件库 - react-native-remote-font 其它(提效、工具&amp;hellip;) 探究 代码规范&#xA;React Native 编码提效 on VSCode&#xA;用脚手架 制作一个RN库 放npm(含踏坑记录)&#xA;贡献给react-native的第一个PR&#xA;React学习收获&#xA;学习《React Hooks 核心原理与实战》笔记 常用hooks依赖检查,从源头提醒避免奇葩bug &amp;hellip; npm 好用工具&#xA;patch-package 补丁工具使用 &amp;hellip; 从0到1用Jenkins实现对RN项目一键打包、发布</description>
</item>
<item>
<title>React 学习</title>
Expand Down
77 changes: 77 additions & 0 deletions public/posts/RN/base-components/BaseNavBar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { StyleSheet, Text, TouchableOpacity, View } from "react-native";
import React from "react";
import { getStatusBarHeight } from "app/utils/index";
import HBImage from "../image/HBImage";
import { px2dp } from "../../utils/ScreenUtils";
import { Actions } from "react-native-router-flux";

const BaseNavBar = ({ children, title, shouldHideBack, backClicked }) => {
return (
// 状态+导航栏 容器
<View style={styles.container}>
{/* 导航栏 */}
<View style={styles.navContainer}>
{/* left 返回按钮 */}
{shouldHideBack ? null : (
<TouchableOpacity
style={{ width: 36, zIndex: 1 }}
onPress={() => {
backClicked ? backClicked() : Actions.pop();
}}
>
<HBImage
source={require("app/img/navigationBar/icon-back-black.png")}
style={{
marginLeft: px2dp(12),
width: 21,
height: 21,
marginTop: px2dp(1.5),
}}
/>
</TouchableOpacity>
)}

{/* 标题 */}
{title && (
<View style={styles.titleContainer}>
<Text style={styles.title}>{title}</Text>
</View>
)}

{/* 其它内容 e.g.右侧按钮 */}
{children}
</View>
</View>
);
};

export default BaseNavBar;

const styles = StyleSheet.create({
container: {
width: "100%",
height: getStatusBarHeight() + 44,
backgroundColor: "#fff",
},

navContainer: {
width: "100%",
marginTop: getStatusBarHeight(),
height: 44,
backgroundColor: "#fff",
flexDirection: "row",
alignItems: "center",
},
titleContainer: {
position: "absolute",
width: "100%",
justifyContent: "center",
alignItems: "center",
},
title: {
fontSize: px2dp(18),
color: "#333",
textAlignVertical: "center",
lineHeight: 44,
},
});
50 changes: 50 additions & 0 deletions public/posts/RN/base-components/LeftUpBackButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from "react";
import HBImage from "app/components/image/HBImage";
import { TouchableOpacity, View } from "react-native";
import { px2dp } from "app/utils/ScreenUtils";
import { Actions } from "react-native-router-flux";
import * as indexUtil from "app/utils/index";

/**
* 返回按钮
* @param {*} props onPress,
* @returns
*/
const LeftUpBackButton = ({ onPress, iconType }) => {
return (
<TouchableOpacity
style={{
zIndex: 999,
position: "absolute",
top: indexUtil.getStatusBarHeight(),
width: px2dp(50),
height: 44,
justifyContent: "center",
left: 0,
}}
onPress={() => {
if (onPress) {
onPress();
} else {
Actions.pop();
}
}}
>
<HBImage
source={
iconType == "white"
? require("app/img/Status_bar_return.png")
: require("app/img/navigationBar/icon-back-black.png")
}
style={{
marginLeft: px2dp(12),
width: px2dp(11),
height: px2dp(19),
marginTop: px2dp(1.5),
}}
/>
</TouchableOpacity>
);
};

export default LeftUpBackButton;
Loading

0 comments on commit cd2529c

Please sign in to comment.