码巢引擎2026年开发文档
00-开发规范
后端规范
README
后端开发手册
前端规范
README
TypeScript最佳实践
前端布局规范
前端页面模板
前端颜色与组件规范
核心规范
组件配置手册
问题排查指南
页面模板
最佳实践
README
bp-20260223-m7ps
图片上传优化总结
BUG自动记录系统使用指南
README
TYPE_SAFETY_GUIDE
常见BUG知识库
常见BUG知识库
开发前检查清单
开发安全规范
开发规范-完整版-含FutureBirdAadminAi部署
数据模型字典
文档分类规范
文档标准化规范
文档模板-基础版
文档模板-技术版
类型安全快速参考卡
类型安全规范体系
规范更新指南
过期文档清理机制
错误处理规范
错误预防指南
常见BUG知识库
常见BUG知识库
01-快速开始
Gitee快速开始
README
协作快速开始
快速开始
质量保证快速开始
02-部署指南
Docker更新指南
Docker部署
FutureBirdAadminAi部署指南
FutureBirdAadminAi部署问题分析
README
发布指南
宝塔Docker部署教程
宝塔PM2部署教程
宝塔图形化部署教程
快速发布指南
数据库和依赖变更处理指南
构建和发布
构建标准
构建检查清单
生产部署快速开始
生产部署方案
生产部署标准
生产部署检查清单
程序备份性能
自动修复和发布指南
自动化发布命令使用指南
部署快速开始
部署指南
项目更新部署指南
03-开发指南
Git凭据配置
Git推送规则
Git自动配置
README
全局样式
协作设置
定时任务
开发指南
开发流程
开发环境标准
技术改进
贡献指南
项目目录树
项目目录结构
04-API文档
API接口文档
README
hr-api
企业API
05-数据库
DATABASE_SCHEMA
README
分区指南
数据库字典
数据持久化
数据模型统一
数据迁移
06-架构设计
RBAC-PERMISSIONS
README
SaaS客户引导流程设计
companyId统一规范
employee-permission-system-design
enterprise-data-linkage
仓库实现总结
仓库模式
企业管理端员工权限系统分析
前端架构
前端重构总结
员工权限系统评估报告
员工管理菜单重构方案
权限系统混乱问题分析
架构优化计划
架构使用指南
架构结构
架构结构
状态管理
用户身份管理体系
系统架构
面试管理模块重构规划
项目技术栈
07-测试质量
README
测试修复标准
测试报告
质量保证系统
08-版本管理
CHANGELOG
README
VERSION_RULES
09-配置指南
README
SMTP配置指南
主题切换指南
渠道配置指南
环境变量指南
环境隔离
12-项目记忆
README
知识库导入指南
记忆系统指南
13-迁移指南
README
备份迁移指南
管理员迁移指南
迁移快速开始
17-其他
README
压缩摘要
18-开放平台
01-架构设计
02-API接口设计
03-安全机制
04-前端设计
05-数据库设计
开放平台API指南
开放平台API说明
19-智能进化
AI执行规则
AI进化机制
README
自动化实现总览
黄金规则
40-操作教程
README
微信公众号域名配置指南
微信本地开发调试指南
44-技能文件
alipay-payment-integration
references
checklist
SKILL
audio
python
README
typescript
README
SKILL
database
python
README
typescript
README
SKILL
design-style-thinking
SKILL
doctor
references
sql-patterns
SKILL
document-generation
python
README
SKILL
email
SKILL
embedding
python
README
typescript
README
SKILL
expo-advanced
references
audio-record-play
file-upload
masonry-layout
save-to-gallery
top-tab-navigation
SKILL
feishu-base
SKILL
feishu-message
SKILL
fetch-url
python
README
typescript
README
SKILL
frontend-design
LICENSE
SKILL
FutureBird-coding-web-performance-best-practice
SKILL
general-dev-preview
references
web-preview
SKILL
image-generation
python
README
typescript
README
SKILL
knowledge
references
python
README
typescript
README
cli
SKILL
llm
python
README
typescript
README
SKILL
miniapp-upload-asr
SKILL
pptx-generation
python
README
SKILL
project-memory-loader
scripts
project_memory_loader
SKILL
repair
scripts
merge-commit-map
SKILL
shadcn-web-base-theme
assets
colors
amber
artistic-green
bento-blue
blue
cyan
emerald
fuchsia
gray
green
indigo
lime
low-pink
neutral
orange
purple
red
retro-brown
rose
sky
supbase-green
teal
tech-purple
vintage-grey
violet
yellow
fonts
business
classic
playful
radius
2xl
2xs
lg
md
none
sm
xl
xs
shadow
artistic
bento
cool
retro
superbase
tech
tool
vintage
default
references
colors
fonts
quick
radius
shadows
scripts
theme
SKILL
package
skill-creator-coze
scripts
init_skill
quick_validate
SKILL
storage
python
README
typescript
README
SKILL
supabase
assets
supabase-client
supabase-client
references
_future
asset-supabase-browser
asset-supabase-config-inject
asset-supabase-config-route
python-auth
python-realtime
python-storage
typescript-auth
typescript-realtime
typescript-storage
typescript-supabase-browser
typescript-supabase-config-inject
typescript-supabase-config-route
python
README
database
edge-functions
orm-model-guide
supabase_client
typescript
README
database
drizzle-schema-guide
edge-functions
supabase-client
cli
rls
SKILL
supabase-auth
references
typescript
supabase-browser
supabase-config-inject
supabase-config-route
auth-config
verify-session
SKILL
ui-design-ref
reference
3D黏土风
克莱因蓝高定风
暗黑科技风
杂志风
极光柔和
柔和卡片
玻璃拟态
纯白极简风
自然有机
SKILL
ui-ux-pro-max
scripts
core
design_system
search
SKILL
vercel-composition-patterns
rules
architecture-avoid-boolean-props
architecture-compound-components
patterns-children-over-render-props
patterns-explicit-variants
react19-no-forwardref
state-context-interface
state-decouple-implementation
state-lift-state
AGENTS
SKILL
vercel-react-best-practices
rules
advanced-event-handler-refs
advanced-init-once
advanced-use-latest
async-api-routes
async-defer-await
async-dependencies
async-parallel
async-suspense-boundaries
bundle-barrel-imports
bundle-conditional
bundle-defer-third-party
bundle-dynamic-imports
bundle-preload
client-event-listeners
client-localstorage-schema
client-passive-event-listeners
client-swr-dedup
js-batch-dom-css
js-cache-function-results
js-cache-property-access
js-cache-storage
js-combine-iterations
js-early-exit
js-hoist-regexp
js-index-maps
js-length-check-first
js-min-max-loop
js-set-map-lookups
js-tosorted-immutable
rendering-activity
rendering-animate-svg-wrapper
rendering-conditional-render
rendering-content-visibility
rendering-hoist-jsx
rendering-hydration-no-flicker
rendering-hydration-suppress-warning
rendering-svg-precision
rendering-usetransition-loading
rerender-defer-reads
rerender-dependencies
rerender-derived-state-no-effect
rerender-derived-state
rerender-functional-setstate
rerender-lazy-state-init
rerender-memo-with-default-value
rerender-memo
rerender-move-effect-to-event
rerender-simple-expression-in-memo
rerender-transitions
rerender-use-ref-transient-values
server-auth-actions
server-cache-lru
server-cache-react
server-dedup-props
server-parallel-fetching
server-serialization
AGENTS
SKILL
video-edit
python
README
typescript
README
SKILL
video-generation
python
README
typescript
README
SKILL
volcano-ark
SKILL
web-design-guidelines
SKILL
web-search
python
README
typescript
README
SKILL
webrtc-best-practice
SKILL
websocket-guide
references
nextjs
nodejs
SKILL
wechat-bot
SKILL
wechat-official-account
SKILL
README
README
未来鸟:企业数字化转型奔腾的力量!
-
+
首页
masonry-layout
# 瀑布流布局标准 (Masonry Layout SOP) **核心目标**:实现 Pinterest 风格,既要防止"摩天大楼"毁版面,又要保证足够的参差感(高低错落)。 ## 1. 数据预处理与高度限制算法 > ⚠️ **视觉优化策略**:为了保证瀑布流的"错落感",**大幅放宽宽高比限制**。允许更扁的横图(制造断层)和适度长的竖图(制造流动感)。 ```typescript // utils/masonry.ts export interface MasonryItem { id: string; imageUrl: string; aspectRatio: number; // 宽/高 title?: string; } // 1. 视觉修正后的高度计算器 export function getOptimizedDimensions( originalAspectRatio: number, columnWidth: number ) { // Visual V2 核心优化:拉大高低反差范围 // Min 0.5: 允许最高为宽度的 2 倍 (长卡片) -> 制造流动感 // Max 2.0: 允许最扁为宽度的 0.5 倍 (短卡片) -> 制造断层 const CLAMPED_RATIO = Math.min(Math.max(originalAspectRatio, 0.5), 2.0); return { height: columnWidth / CLAMPED_RATIO, isClamped: originalAspectRatio < 0.5 }; } // 2. 贪心分配算法 (Greedy Layout) export function distributeItems<T extends MasonryItem>( items: T[], columnWidth: number, columns = 2 ) { const FOOTER_HEIGHT = 64; // 标题+头像区域高度 const columnArrays: T[][] = Array.from({ length: columns }, () => []); const columnHeights: number[] = Array(columns).fill(0); items.forEach((item) => { const { height: imgHeight } = getOptimizedDimensions(item.aspectRatio || 1, columnWidth); const totalItemHeight = imgHeight + FOOTER_HEIGHT; // 永远放入当前最矮的那一列 const shortestIndex = columnHeights.indexOf(Math.min(...columnHeights)); columnArrays[shortestIndex].push(item); columnHeights[shortestIndex] += totalItemHeight; }); return columnArrays; } /** * [CRITICAL MOCK GENERATOR] * 开发阶段必须使用此函数生成测试数据! * 强制混合三种极端比例,严禁使用统一比例,否则无法验证瀑布流效果。 */ export function generateMockMasonryData(count = 20): MasonryItem[] { return Array.from({ length: count }).map((_, i) => { // 强制分布逻辑: // - 20% 超扁 (16:9, ratio ~1.7) -> 制造缺口 // - 50% 常规 (3:4 ~ 1:1, ratio 0.75 ~ 1.0) -> 填充基底 // - 30% 超长 (9:16, ratio ~0.56) -> 制造瀑布流 let ratio; const seed = Math.random(); if (seed < 0.2) { ratio = 1.6 + Math.random() * 0.2; // 扁图 } else if (seed < 0.7) { ratio = 0.75 + Math.random() * 0.4; // 常规图 } else { ratio = 0.5 + Math.random() * 0.1; // 长图 } // 生成对应尺寸的 picsum 图片,防止拉伸 const w = 400; const h = Math.floor(w / ratio); return { id: String(i), imageUrl: `https://picsum.photos/${w}/${h}?random=${i}`, // 关键:URL带真实尺寸 aspectRatio: ratio, title: seed < 0.3 ? `长标题测试 ${i} - 这是一个跨越多行的标题示例,用于测试底部高度自适应` : `短标题 ${i}`, }; }); } ``` ## 2. 组件实现规范 采用 `ScrollView` + `Flex Row` 结构,并强制使用 `expo-image` 优化性能。 ```tsx // components/MasonryGrid.tsx import React, { useMemo } from 'react'; import { View, ScrollView, useWindowDimensions, StyleSheet, Pressable } from 'react-native'; import { Image } from 'expo-image'; import { distributeItems, getOptimizedDimensions, MasonryItem } from '@/utils/masonry'; import { ThemedText } from '@/components/ThemedText'; import { useTheme } from '@/hooks/useTheme'; export function MasonryGrid({ data }: { data: MasonryItem[] }) { const { width } = useWindowDimensions(); const { theme } = useTheme(); // 布局常量 const COLUMNS = 2; const GAP = 12; const PADDING = 16; const COLUMN_WIDTH = (width - PADDING * 2 - GAP * (COLUMNS - 1)) / COLUMNS; // 使用 useMemo 缓存计算结果 const columnData = useMemo(() => distributeItems(data, COLUMN_WIDTH, COLUMNS), [data, COLUMN_WIDTH]); return ( <ScrollView contentContainerStyle={[styles.container, { padding: PADDING }]}> <View style={[styles.columnsProps, { gap: GAP }]}> {columnData.map((colItems, colIndex) => ( <View key={colIndex} style={[styles.column, { gap: GAP }]}> {colItems.map((item) => { // 获取修正后的高度 const { height } = getOptimizedDimensions(item.aspectRatio, COLUMN_WIDTH); return ( <Pressable key={item.id} style={[styles.card, { backgroundColor: theme.surface }]}> {/* 图片容器 */} <View style={[styles.imageWrapper, { height, width: COLUMN_WIDTH }]}> <Image source={item.imageUrl} style={{ flex: 1 }} contentFit="cover" transition={200} /> </View> <View style={styles.textWrapper}> <ThemedText numberOfLines={2} variant="caption"> {item.title} </ThemedText> </View> </Pressable> ); })} </View> ))} </View> </ScrollView> ); } const styles = StyleSheet.create({ container: { flexGrow: 1 }, columnsProps: { flexDirection: 'row' }, column: { flex: 1 }, card: { borderRadius: 12, overflow: 'hidden', marginBottom: 0 }, imageWrapper: { overflow: 'hidden', backgroundColor: '#e1e1e1' }, textWrapper: { padding: 8 }, }); ``` ## 禁止事项 - 数据的图片宽高比 (`aspectRatio`) **必须**随机生成多种比例,**绝对禁止**全部使用 1:1 方图,否则无法验证交错排列的视觉效果 - **严禁**使用 via.placeholder.com(该服务已失效)
未来鸟
2026年7月27日 10:55
转发
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
分享
链接
类型
密码
更新密码
有效期
Markdown文件
Word文件
PDF文档(打印)
AI