-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
75 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 1.2.0 | ||
|
||
* Export experimental inline FC | ||
|
||
## 1.1.0 | ||
|
||
* Add optional parameter constructor for "Ref" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export 'src/fc_compat_v0.dart' | ||
show defineFC, useEffect, useImperativeHandle, useBuildContext; | ||
show useEffect, useImperativeHandle, useBuildContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export './src/fc_define_fc.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import 'package:flutter/widgets.dart'; | ||
|
||
import 'fc_core.dart'; | ||
export 'fc_foundation.dart' show useState; | ||
|
||
typedef WidgetKeyBuilder<Props> = Widget Function( | ||
BuildContext context, Props? props, Key? key); | ||
typedef MemoizedFC<Props> = Widget Function({Props? props, Key? ref, Key? key}); | ||
typedef ForwardRefFC<Props> = Widget Function( | ||
BuildContext context, Props? props, Key? ref); | ||
typedef FC<Props> = Widget Function(BuildContext context, Props? props); | ||
|
||
var kDangerousFCIndex = 0; | ||
int nextFCId() => ++kDangerousFCIndex; | ||
|
||
class FCPropsWidget<Props> extends Widget implements FCWidget { | ||
final String name; | ||
final WidgetKeyBuilder<Props> builder; | ||
final Props props; | ||
final Key? ref; | ||
|
||
const FCPropsWidget( | ||
this.builder, | ||
this.props, | ||
this.ref, | ||
this.name, { | ||
super.key, | ||
}); | ||
|
||
@override | ||
Type get runtimeType => FCType("${super.runtimeType}\$$name"); | ||
|
||
@override | ||
Element createElement() => FCElement<FCPropsWidget>(this); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return builder(context, props, ref); | ||
} | ||
} | ||
|
||
class FCType implements Type { | ||
final String name; | ||
FCType(this.name); | ||
|
||
String get fullName => "FCType_$name"; | ||
|
||
@override | ||
int get hashCode => fullName.hashCode; | ||
|
||
@override | ||
bool operator ==(Object other) { | ||
return other is FCType && other.name == name; | ||
} | ||
|
||
@override | ||
String toString() { | ||
return "${super.toString()}(fullName=$fullName)"; | ||
} | ||
} | ||
|
||
MemoizedFC<Props> defineFC<Props>(FC<Props> fn) { | ||
final name = "defineFC_${nextFCId()}"; | ||
return ({props, ref, key}) => FCPropsWidget( | ||
(context, props, ref) => fn(context, props), props, ref, name, | ||
key: key); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters