joshaber / few.swift Goto Github PK
View Code? Open in Web Editor NEWViews as functions of their state.
License: MIT License
Views as functions of their state.
License: MIT License
The repo is still using Swift 2, should upgrade to Swift 3 or 4.
Not sure if it has just been a long week but I'm struggling to get the demo iOS project to update rebuild a framework of my changes ๐ฌ
It looks like it is looking for the Few.framework
in a build/Debug-iphoneos
directory but that does not exist. I have tried building/running/archiving the framework targets and no frameworks get put there. Is there something I am missing?
Some additional documentation on how to download, install, and run the project would be nice. Plus the same on including Few in my own project.
If I create a root app component with 2 child components, those components flexbox layouts are computed first as independent flexbox layout calls and not as children of the app component's layout. In my case that means they receive no width. If instead I wrap them in Elements that are children of the app component it works as expected. Is this by design? Do I need to create wrapping elements around components to handle certain layout cases?
We use flexbox for layout but different terminology. We should use the same so it's easy to share existing knowledge and resources.
This'll obviously require changes to SwiftBox.
It's pretty excellent, and it's just begging for a React-style API. Few can make this happen. @joshaber Any interest?
No commits in 2 years. I'm guessing this is dead, right?
Should we allow component state to be changed from a background thread? Should it do realization, layout, or diffing on a background thread?
Currently it's really just setting frames like the Bad Old Days. It'd be nice if it were nicer.
Should we coalesce update calls, maybe using a display link?
Need to do the equivalent of #65. I'll do it.
Because Swift currently does not support non-generic subclasses, i thought about creating components by implementing a ComponentSpec
or ComponentType
protocol. We can use associated types to infer the state type. We only need to know when the state changes, maybe we can make a State
type that you can observe.
After implementing ComponentSpec
you can use the method construct
to create a Component<Spec.StateType>
To receive lifecycle events we could add an LifeCycleEvent
enum, and add lifeCycleStateChanged(event: LifeCycleEvent)
for receiving those events.
I'm trying to install Few.swift via Carthage and I'm running into some xcodebuild issues. I'm on Xcode 7.1 (7B91b).
Here's my Cartfile:
github "joshaber/Few.swift" "swift-2"
Here's the output when building iOS:
carthage update --platform iOS
*** Fetching Few.swift
*** Fetching SwiftBox
*** Checking out SwiftBox at "c316daebb98237a0c20c5fc7cb92028f44809861"
*** Checking out Few.swift at "12406946e2b11b3f0848235544ff6aaf97618f6b"
*** xcodebuild output can be found in /var/folders/s6/qx12s0856zg2zhsnx_14sqd40000gn/T/carthage-xcodebuild.ZyIMzF.log
*** Building scheme "SwiftBox-iOS" in SwiftBox.xcodeproj
*** Building scheme "Few-iOS" in Few.xcworkspace
** BUILD FAILED **
The following build commands failed:
CompileSwift normal x86_64 /Users/mark/projects/foo/Carthage/Checkouts/Few.swift/FewCore/Element.swift
CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
(2 failures)
/Users/mark/projects/foo/Carthage/Checkouts/Few.swift/FewCore/Element.swift:69:234: error: type 'Direction' has no member 'Row'
A shell task failed with exit code 65:
** BUILD FAILED **
The following build commands failed:
CompileSwift normal x86_64 /Users/mark/projects/foo/Carthage/Checkouts/Few.swift/FewCore/Element.swift
CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
(2 failures)
And here's the output when I build for Mac:
โ carthage update --platform Mac
*** Fetching Few.swift
*** Fetching SwiftBox
*** Checking out SwiftBox at "c316daebb98237a0c20c5fc7cb92028f44809861"
*** Checking out Few.swift at "12406946e2b11b3f0848235544ff6aaf97618f6b"
*** xcodebuild output can be found in /var/folders/s6/qx12s0856zg2zhsnx_14sqd40000gn/T/carthage-xcodebuild.lbVR1l.log
*** Building scheme "SwiftBox-Mac" in SwiftBox.xcodeproj
*** Building scheme "Few-Mac" in Few.xcworkspace
** BUILD FAILED **
The following build commands failed:
CompileSwift normal x86_64 /Users/mark/projects/foo/Carthage/Checkouts/Few.swift/FewCore/Element.swift
CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
(2 failures)
/Users/mark/projects/foo/Carthage/Checkouts/Few.swift/FewCore/Element.swift:39:21: error: type of expression is ambiguous without more context
/Users/mark/projects/foo/Carthage/Checkouts/Few.swift/FewCore/Element.swift:69:234: error: type 'Direction' has no member 'Row'
A shell task failed with exit code 65:
** BUILD FAILED **
The following build commands failed:
CompileSwift normal x86_64 /Users/mark/projects/foo/Carthage/Checkouts/Few.swift/FewCore/Element.swift
CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
(2 failures)
FWIW In Carthage/Checkouts/SwiftBox/SwiftBox/Node.swift
, I see this:
public enum Direction: UInt32 {
case Inherit = 0
case LeftToRight = 1
case RightToLeft = 2
}
No idea if that's the enum it's looking at, but if it is it certainly doesn't have a Row
member.
Is there some mismatch between Few.swift and Swiftbox going on? Some kind of Cartfile confusion or something? Admittedly, I have never used either of these libraries, so I'm exactly sure what I'm looking at. This library looks great - I've got a prototype build of a Redux Swift implementation and would love to hook it up with Few.swift.
Thoughts?
@joshaber Sometimes it would be nice to be able to customize a Component's behavior from outside, after the render. For example I want to set some scroll view insets after a component is realized, and subclassing component seems like a bit much. What do you think?
I can't find any info about creating multi-line text. Is that possible?
Now that protocols can have concrete implementations, we should re-visit whether Few can be designed around value types and protocols. โจ
It would be great if we could wrap UINavigationController in an Navigator
(Navigation Component). Not sure how what the api would be.
@joshaber We call reloadData()
every time we diff a TableView, and that kills our selection. I'll work on this one โ just putting it here as a reminder.
Current thinking is we need to make Element
equatable, and not call reloadData()
unless our row data has actually changed. Thoughts?
Maybe we can implement something like react.animate. updateState
with an extra option to add an animation.
Is there any way to do something like this? In my case I need to use a vanilla UITableView
and I'd like to compute the heights for all my elements without creating views for them. Can we make assembleLayoutNode()
public, since it has no side effects?
It should support animations somehow.
Currently each component re-renders itself when its state changes. This works, but it's less than ideal.
Consider a component A which renders a component B. If both update their state in the same runloop, component B will be rendered twice: once by itself because of its state update, and once when component A re-renders itself.
We should start each re-render from the topmost dirty component.
(I don't think there are any correctness problems here, but it's certainly less performant.)
Currently there's a 1-to-1 correspondence between Element
s and views. But that doesn't necessarily have to be the case. A lot of Element
s exist in the hierarchy for layout reasons only. They don't actually need to exist as reified views.
My current thinking is that Element
shouldn't create a view but be used only for layout.
Pointed out by @coenert: #33 (comment)
They'll get applied when the first diff is applied, but they're often not assigned as they should be in createView
.
The Input
element does not seem to follow the .childAlignment(.Stretch)
property. I have attached a screenshot (I'm bad at designing but these colors are used for clarity of the issue ๐) and the example view code. I believe my code is right as the "Welcome!" Label
and the bottom border views are stretched. BUT please let me know if it is something with just my code ๐
return View(backgroundColor: UIColor.lightGrayColor())
.justification(.FlexStart)
.childAlignment(.Center)
.direction(.Column)
.children([
View(backgroundColor: UIColor.orangeColor())
.childAlignment(.Stretch)
.direction(.Column)
.width(300)
.margin(Edges(left: 0, right: 0, bottom: 0, top: 80))
.padding(Edges(left: 20, right: 20, bottom: 20, top: 20))
.children([
// Label
{ () -> Label in
let l = Label("Welcome!",
textColor: UIColor.darkGrayColor(),
font: UIFont.boldSystemFontOfSize(26))
.margin(Edges(left: 0, right: 0, bottom: 20, top: 0))
l.selfAlignment(.Center)
return l
}(),
// Input - Email
Input(textColor: UIColor.blackColor(),
placeholder: "Email",
keyboardType: UIKeyboardType.EmailAddress,
returnKeyType: UIReturnKeyType.Next,
borderStyle: UITextBorderStyle.RoundedRect)
.margin(Edges(left: 0, right: 0, bottom: 0, top: 0)),
// Border View
View(backgroundColor: UIColor.darkGrayColor())
.height(1)
.margin(Edges(left: 0, right: 0, bottom: 20, top: 2)),
// Input - Password
Input(textColor: UIColor.blackColor(),
placeholder: "Password",
returnKeyType: UIReturnKeyType.Done,
secure: true),
// Border View
View(backgroundColor: UIColor.darkGrayColor())
.height(1)
.margin(Edges(left: 0, right: 0, bottom: 10, top: 2))
])
why
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.