Skip to content

Commit

Permalink
[opt][2.2.x]: 1、优化 BrnPopupListWindow onItemClick 逻辑问题;2、changeLog; 3…
Browse files Browse the repository at this point in the history
…、优化 Demo (#157)
  • Loading branch information
violinday authored Apr 1, 2022
1 parent b317ec9 commit f98b052
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 36 deletions.
17 changes: 14 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
## [2.1.0-nullsafety.0] - 2022-3-10


## [2.1.0-nullsafety] - 2022-4-1

### Changed

#### base

- **Breaking change**: Sound null safety support, thanks to @leftcoding #39#33 @donywan #20 @laiiihz #80#64#59#32#14 @kalifun #36 @jojinshallar #81#75#65#62#56#42 @junlandroid #73 @Kenneth #53 @HappyImp #55 @kkkman22 #23 @AlexV525 #30
- **Breaking change**: Refer to the dart language specification to optimized constant and enum naming.
- Replace <code>DIN Font</code> with <code>Bebas Font</code> .
- Add build test thank to **AlexV525**.

#### components

- **Breaking change**: remove <code>BrnHorizontalStepsManager</code> and put function <code>forwardStep()</code> <code>backStep()</code> into <code>BrnStepsController</code> thanks to leftcoding.
- **Breaking change**: remove <code>BrnDialogStyle</code> and replace with <code>BrnDialogConfig</code>.
- <code>BrnCalendarView</code>: add <code>BrnCalendarView.single()</code> and <code>BrnCalendarView.range()</code> constructor and had its argument <code>startEndDateChange</code> removed.
Expand All @@ -17,17 +20,25 @@
- <code>BrnScrollableTextDialog</code>: remove Navigator.pop(context) in <code>onSubmit()</code> and hand it over to external processing (user).
- <code>BrnBubbleText</code>: add attribute <code>bgColor</code> and <code>textStyle</code>.
- <code>BrnPairInfoTable</code>: add attribute <code>defaultVerticalAlignment</code>.
- <code>BrnDialog</code>: remove <code>BrnDialogStyle</code> and replace with <code>BrnDialogConfig</code>.
- <code>BrnSingleSelectDialog</code> : add attribute <code>messageText</code> and <code>messageWidget</code>.




### Fixed

- Fix example error [#71](https://github.com/LianjiaTech/bruno/issues/71) thanks to **leftcoding** fixing this issue.

- Fix <code>BrnPickerTitleConfig</code> <code>titleContent</code> setting is invalid [#70](https://github.com/LianjiaTech/bruno/issues/70).

- Optimize <code>BrnPopupWindow </code> <code>onItemClick</code> logic [#57 ](https://github.com/LianjiaTech/bruno/issues/57) .

- Fix <code>BrnDialog</code> is obscured by keyboard [#7](https://github.com/LianjiaTech/bruno/issues/7) .

- Fix <code>BrnTextSelectFormItem</code> set <code>titlePaddingLg</code> doesn't work [#108](https://github.com/LianjiaTech/bruno/issues/108).

- Fix the bottom text of <code>BrnBottomTabBar</code> cannot be displayed in some cases [#141](https://github.com/LianjiaTech/bruno/issues/141).



Thanks again to **leftcoding**, **jojinshallar**, **laiiihz**, **donywan**, **kalifun**, **junlandroid**, **Kenneth**, **HappyImp**, **kkkman22** , **a1017480401** and **Alex**.
Expand Down
2 changes: 2 additions & 0 deletions docs/components/tips/BrnPopupWindow/BrnPopupWindow.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,12 @@ RaisedButton(

![image-20211028170442805](./img/BrnPopupWindowDemo3.png)

注意:onItemClick 必须返回 true 或 false 决定是否拦截点击事件, 如果为 true 拦截事件,则内部不再走 pop 消失逻辑。
```dart
BrnPopupListWindow.showPopListWindow(context, _leftKeylist0,
data: ['选项一', '选项二', '选项三'], onItemClick: (index, item) {
BrnToast.show(item, context);
return false;
}, hasCloseIcon: true);
```

Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class BottomTabbarExampleState extends State<BottomTabbarExample>
home: Scaffold(
appBar: BrnAppBar(
title: 'BottomTabBar',
backLeadCallback: (){
Navigator.pop(context);
},
),

/// 首先定义一个BottomTabBar容器
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ class BrnTextButtonPanelExample extends StatelessWidget {
nameList: ['操作1', '操作2', '操作3', '操作4', '操作5', '操作6'],
popDirection: BrnPopupDirection.top,
onTap: (index) {
BrnToast.show('第$index个操作', context);
BrnDialogManager.showSingleButtonDialog(context, message: 'index $index clicked!', label: 'OK', onTap: (){
Navigator.pop(context);
});
},
),
Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ class _NavBarPageState extends State<NavBarPage> with TickerProviderStateMixin {
iconPressed: () {
BrnPopupListWindow.showPopListWindow(context, actionKey,
offset: 10, data: ["aaaa", "bbbbb"], onItemClick: (index, item){
BrnDialogManager.showConfirmDialog(context, cancel: 'cancel', confirm: 'confirm', message: 'message');
BrnDialogManager.showConfirmDialog(context, cancel: 'cancel', confirm: 'confirm', message: 'message', onCancel: (){
Navigator.pop(context);
});
return true;
}, onDismiss: (){
BrnToast.show('onDismiss', context);
});
Expand Down Expand Up @@ -516,6 +519,7 @@ class _NavBarPageState extends State<NavBarPage> with TickerProviderStateMixin {
data: ["aaaa", "bbbbb"],
onItemClick: (index, data) {
BrnDialogManager.showConfirmDialog(context, cancel: 'cancel', confirm: 'confirm', message: 'message');
return true;
},
onDismiss: (){
BrnToast.show('onDismiss', context);
Expand Down
17 changes: 8 additions & 9 deletions lib/src/components/button/collection/brn_button_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,17 @@ class _BrnButtonPanelState extends State<BrnButtonPanel> {
fontSize: 16));
},
popDirection: widget.popDirection,
onItemClickInterceptor: (index, item) {
// 按钮不可用的时候,点击无响应;
if (_secondaryButtonList[index + 2].isEnable) {
return false;
} else {
return true;
}
},
onItemClick: (index, item) {
// 按钮不可用的时候,点击无响应;
if (widget.secondaryButtonOnTap != null) {
widget.secondaryButtonOnTap!(index + 2);
if (_secondaryButtonList[index + 2].isEnable) {
widget.secondaryButtonOnTap!(index + 2);
return false;
} else {
return true;
}
}
return false;
});
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,11 @@ class _BrnTextButtonPanelState extends State<BrnTextButtonPanel> {
offset: 10,
popDirection: widget.popDirection,
data: list, onItemClick: (index, item) {
Navigator.pop(context);
if (widget.onTap != null) {
widget.onTap!(index + 3);
}
return true;
}, onDismiss: () {
setState(() {
_isExpanded = false;
Expand Down
31 changes: 9 additions & 22 deletions lib/src/components/popup/brn_popup_window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -455,16 +455,11 @@ class BrnPopupRoute extends PopupRoute {
Duration get transitionDuration => _duration;
}

/// popup 中每个 Item 被点击时的回调,
/// popup 中每个 Item 被点击时的回调,并决定是否拦截点击事件
/// [index] Item 的索引
/// [item] Item 内容
typedef BrnPopupListItemClick = void Function(int index, String item);

/// popup 中每个 Item 被点击时,是否拦截点击事件
/// [index] Item 的索引
/// [item] Item 内容
/// 返回 true 则拦截点击事件,不再回调 [onItemClick]
typedef BrnPopupListItemClickInterceptor = bool Function(int index, String item);
/// 返回 true 则拦截点击事件,不再走 pop 逻辑
typedef BrnPopupListItemClick = bool Function(int index, String item);

/// popup 用于构造自定义的 Item
/// [index] Item 的索引
Expand All @@ -488,7 +483,6 @@ class BrnPopupListWindow {
BrnPopupDirection popDirection = BrnPopupDirection.bottom,
BrnPopupListItemBuilder? itemBuilder,
BrnPopupListItemClick? onItemClick,
BrnPopupListItemClickInterceptor? onItemClickInterceptor,
VoidCallback? onDismiss,
}) {
TextStyle textStyle = TextStyle(
Expand Down Expand Up @@ -529,8 +523,8 @@ class BrnPopupListWindow {
children:
_getItems(context, minWidth, maxWidth, itemBuilder, textStyle, data!,
(index, item) {
if (onItemClickInterceptor != null) {
bool isIntercept = onItemClickInterceptor(index, item);
if (onItemClick != null) {
bool isIntercept = onItemClick(index, item);
if (isIntercept) return;
}
Navigator.pop(context, {'index': index, 'item': item});
Expand All @@ -544,9 +538,6 @@ class BrnPopupListWindow {
borderColor: borderColor,
spaceMargin: spaceMargin,
))).then((result) {
if (onItemClick != null && result != null) {
onItemClick(result['index'], result['item']);
}
if (onDismiss != null) {
onDismiss();
}
Expand All @@ -566,7 +557,6 @@ class BrnPopupListWindow {
BrnPopupDirection popDirection = BrnPopupDirection.bottom,
double offset = 0,
BrnPopupListItemClick? onItemClick,
BrnPopupListItemClickInterceptor? onItemClickInterceptor,
VoidCallback? onDismiss}) {
assert(popKey.currentContext != null && popKey.currentContext!.findRenderObject() != null);
if (popKey.currentContext == null || popKey.currentContext!.findRenderObject() == null) return;
Expand Down Expand Up @@ -608,11 +598,11 @@ class BrnPopupListWindow {
child: Column(
children: _getItems(context, minWidth, maxWidth, null, textStyle, data!,
(index, item) {
if (onItemClickInterceptor != null) {
bool isIntercept = onItemClickInterceptor(index, item);
if (onItemClick != null) {
bool isIntercept = onItemClick(index, item);
if (isIntercept) return;
}
Navigator.pop(context, {'index': index, 'item': item});
Navigator.pop(context);
}),
),
),
Expand All @@ -625,9 +615,6 @@ class BrnPopupListWindow {
),
),
).then((result) {
if (onItemClick != null && result != null) {
onItemClick(result['index'], result['item']);
}
if (onDismiss != null) {
onDismiss();
}
Expand All @@ -641,7 +628,7 @@ class BrnPopupListWindow {
BrnPopupListItemBuilder? itemBuilder,
TextStyle textStyle,
List<String> data,
BrnPopupListItemClick onItemClick) {
void Function(int index, String item) onItemClick) {
double textMaxWidth = _getMaxWidth(textStyle, data);
if (textMaxWidth + 52 < minWidth) {
textMaxWidth = minWidth;
Expand Down

0 comments on commit f98b052

Please sign in to comment.