Skip to content

Commit

Permalink
uitable
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <tukon479@gmail.com>
  • Loading branch information
Innei committed Jan 28, 2025
1 parent 9abd5a4 commit ce2ed44
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 12 deletions.
19 changes: 11 additions & 8 deletions apps/mobile/packages/follow-native/example/App.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { ListView } from "follow-native"
import { TableView } from "follow-native"
import { ScrollView } from "react-native"

export default function App() {
return (
<ScrollView contentContainerStyle={{ flex: 1 }} contentInsetAdjustmentBehavior="automatic">
<ListView
items={[
{ id: "1", name: "Hello" },
{ id: "2", name: "World" },
]}
/>
// <ScrollView contentContainerStyle={{ flex: 1 }} contentInsetAdjustmentBehavior="automatic">
// <ListView
// items={[
// { id: "1", name: "Hello" },
// { id: "2", name: "World" },
// ]}
// />
// </ScrollView>
<ScrollView>
<TableView />
</ScrollView>
)
}
2 changes: 1 addition & 1 deletion apps/mobile/packages/follow-native/expo-module.config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"platforms": ["apple", "android", "web"],
"apple": {
"modules": ["ListModule"]
"modules": ["ListModule", "TableViewModule"]
},
"android": {
"modules": ["expo.modules.follownative.ListModule"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Pod::Spec.new do |s|
s.static_framework = true

s.dependency 'ExpoModulesCore'

s.dependency 'SnapKit', '~> 5.7.0'
# Swift/Objective-C compatibility
s.pod_target_xcconfig = {
'DEFINES_MODULE' => 'YES',
Expand Down
39 changes: 38 additions & 1 deletion apps/mobile/packages/follow-native/ios/TableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,41 @@
// Created by Innei on 2025/1/29.
//

import Foundation
import ExpoModulesCore
import UIKit

class FOTableView: ExpoView, UITableViewDataSource, UITableViewDelegate {
var tableView: UITableView!

let data = [
"苹果", "香蕉", "橙子", "葡萄", "蓝莓", "草莓", "西瓜",
]
required init(appContext: AppContext? = nil) {
super.init(appContext: appContext)

tableView = UITableView(frame: UIScreen.main.bounds)
addSubview(tableView)

tableView.dataSource = self
tableView.delegate = self
// 注册 UITableViewCell
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")

// 添加 tableView 到主视图
addSubview(tableView)
}

// UITableViewDataSource 方法
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)

// 配置每一行的内容
cell.textLabel?.text = data[indexPath.row]

return cell
}
}
11 changes: 10 additions & 1 deletion apps/mobile/packages/follow-native/ios/TableViewModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,13 @@
// Created by Innei on 2025/1/29.
//

import Foundation
import ExpoModulesCore

public class TableViewModule: Module {
public func definition() -> ModuleDefinition {
Name("FOTableView")

View(FOTableView.self) {
}
}
}
8 changes: 8 additions & 0 deletions apps/mobile/packages/follow-native/src/TableView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { requireNativeView } from "expo"
import * as React from "react"

const NativeView: React.ComponentType = requireNativeView("FOTableView")

export default function TableView() {
return <NativeView />
}
1 change: 1 addition & 0 deletions apps/mobile/packages/follow-native/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default as ListView } from "./ListView"
export { default as TableView } from "./TableView"

0 comments on commit ce2ed44

Please sign in to comment.