From 6a5af1e4cc8f032963b49805b55fbdf92d70206b Mon Sep 17 00:00:00 2001 From: gruskal Date: Fri, 9 Dec 2022 12:57:47 -0500 Subject: [PATCH 1/4] fix: 3919 3918 3920 --- .../CellView.java | 5 ++ .../HeaderViewFactory.java | 8 ++- .../SearchButton.java | 32 +--------- .../TableView.java | 41 ++----------- .../TableViewFactory.java | 59 ++++++++----------- .../TotalsView.java | 57 ++++++++++++++++++ 6 files changed, 99 insertions(+), 103 deletions(-) diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/CellView.java b/android/src/main/java/com/qliktrialreactnativestraighttable/CellView.java index 52add1a0..d1693c01 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/CellView.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/CellView.java @@ -23,6 +23,7 @@ @SuppressLint("ViewConstructor") public class CellView extends RelativeLayout implements SelectionsObserver { + String type = ""; Content content = null; DataRow row; DataColumn column; @@ -91,6 +92,7 @@ private void createContent(String type, DataColumn dataColumn) { this.setPadding(PADDING, 0, PADDING, 0); break; } + this.type = type; } private void addContentView(String type) { @@ -103,6 +105,9 @@ private void addContentView(String type) { } public void convertCellContentType(String type, DataColumn dataColumn) { + if(this.type.equals(type)) { + return; + } wrapper = null; wrapperLayout = null; column = dataColumn; diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/HeaderViewFactory.java b/android/src/main/java/com/qliktrialreactnativestraighttable/HeaderViewFactory.java index 0f9e6289..9e04694e 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/HeaderViewFactory.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/HeaderViewFactory.java @@ -29,6 +29,7 @@ public class HeaderViewFactory { HeaderViewFactory headerViewFactory; String totalsLabel; boolean topPosition; + boolean bottomPosition; HeaderView headerView = null; TotalsView totalsView = null; TableView tableView; @@ -45,15 +46,16 @@ public List getDataColumns() { return dataColumns; } - public HeaderViewFactory(List dataColumns, List totalsCells, String totalsLabel, boolean topPosition, TableView tableView, HeaderContentStyle contentStyle, Context context) { + public HeaderViewFactory(List dataColumns, List totalsCells, String totalsLabel, String totalsPosition, TableView tableView, HeaderContentStyle contentStyle, Context context) { this.tableView = tableView; this.dataColumns = dataColumns; this.totalsCells = totalsCells; this.totalsLabel = totalsLabel; - this.topPosition = topPosition; + this.topPosition = totalsPosition.equals("top"); + this.bottomPosition = totalsPosition.equals("bottom"); this.headerContentStyle = contentStyle; buildHeader(context); - if (totalsCells != null) { + if (totalsCells != null && !totalsPosition.equals("noTotals")) { buildTotals(context); } } diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/SearchButton.java b/android/src/main/java/com/qliktrialreactnativestraighttable/SearchButton.java index 08ee58cc..03c31a59 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/SearchButton.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/SearchButton.java @@ -13,8 +13,6 @@ public class SearchButton extends androidx.appcompat.widget.AppCompatImageButton final DataColumn column; final TableView tableView; final int defaultColor = Color.TRANSPARENT; - final int pressedColor = Color.parseColor("#595959"); - final int textColor = Color.parseColor("#404040"); public SearchButton(Context context, TableView tableView, DataColumn column) { super(context); @@ -26,38 +24,14 @@ public SearchButton(Context context, TableView tableView, DataColumn column) { this.setBackgroundColor(defaultColor); } - public void handleTouchDown(){ - this.setBackgroundColor(pressedColor); - - icon.setTint(Color.WHITE); - this.setImageDrawable(icon); - postInvalidate(); - } - - - public void handleTouchUp(){ - this.setBackgroundColor(defaultColor); - - icon.setTint(textColor); - this.setImageDrawable(icon); - } - @SuppressLint("ClickableViewAccessibility") @Override public boolean onTouchEvent(MotionEvent event) { int action = event.getAction(); - switch(action) { - case MotionEvent.ACTION_DOWN: - handleTouchDown(); - break; - case MotionEvent.ACTION_CANCEL: - handleTouchUp(); - break; - case MotionEvent.ACTION_UP: - EventUtils.sendOnSearchColumn(tableView, column); - postInvalidate(); - break; + if (action == MotionEvent.ACTION_UP) { + EventUtils.sendOnSearchColumn(tableView, column); + postInvalidate(); } return super.onTouchEvent(event); } diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/TableView.java b/android/src/main/java/com/qliktrialreactnativestraighttable/TableView.java index 4f2ce889..b0811ac3 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/TableView.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/TableView.java @@ -161,42 +161,7 @@ public void setDataColumns(List cols) { TotalsView totalsView = getTotalsView(); if(totalsView != null) { - totalsView.setDataColumns(cols); - // Create new totals when there are new columns - int totalCellCount = totalsView.getChildCount(); - int numMissingCells = dataProvider.dataColumns.size() - totalCellCount; - int numCells = dataProvider.totalsCells.size(); - int j = numCells - numMissingCells; - for(int i = totalCellCount; i < dataProvider.dataColumns.size(); i++) { - DataColumn column = dataProvider.dataColumns.get(i); - TotalsViewCell totalsViewCell = HeaderViewFactory.createTotalsCell(getContext(), column, this); - LinearLayout.LayoutParams totalsParams = new LinearLayout.LayoutParams(column.width, ViewGroup.LayoutParams.MATCH_PARENT); - if (!column.isDim && j < numCells) { - totalsViewCell.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL); - totalsViewCell.setText(dataProvider.totalsCells.get(j).qText); - j++; - } - totalsView.addView(totalsViewCell, totalsParams); - } - // Update totals in case of moved columns - j = 0; - for(int i = 0; i < totalsView.getChildCount(); i++) { - TotalsViewCell viewCell = (TotalsViewCell) totalsView.getChildAt(i); - viewCell.setText(""); - - if(i > dataProvider.dataColumns.size() - 1) { - totalsView.removeView(totalsView); - continue; - } - - DataColumn column = dataProvider.dataColumns.get(i); - viewCell.setColumn(column); - if(!column.isDim && j < dataProvider.totalsCells.size()) { - String newText = dataProvider.totalsCells.get(j).qText; - viewCell.setText(newText != null && newText.length() > 0 ? newText : ""); - j++; - } - } + totalsView.updateTotals(cols, dataProvider); } if(headerView != null) { @@ -225,6 +190,10 @@ public void setDataColumns(List cols) { tableViewFactory.firstColumnHeaderCell.setColumn(cols.get(0)); } + if(tableViewFactory.firstColumnTotalsCell != null) { + tableViewFactory.firstColumnTotalsCell.setText(totalsLabel); + } + if(grabbers != null) { for(GrabberView grabberView : grabbers) { grabberView.setDataProvider(dataProvider); diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/TableViewFactory.java b/android/src/main/java/com/qliktrialreactnativestraighttable/TableViewFactory.java index b1f8d938..8709c29f 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/TableViewFactory.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/TableViewFactory.java @@ -22,8 +22,6 @@ import java.util.List; public class TableViewFactory { - public int extraTopMargin = 0; - public int extraBottomMargin = 0; public HeaderViewFactory headerViewFactory = null; public CustomHorizontalScrollView scrollView = null; public MockVerticalScrollView verticalScrollBar = null; @@ -114,7 +112,8 @@ private void setMockScrollLayouts() { FrameLayout.LayoutParams horizontalFrameLayout = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, (int) PixelUtils.dpToPx(5)); horizontalFrameLayout.gravity = Gravity.BOTTOM; - horizontalFrameLayout.bottomMargin = tableView.totalsHeight; + // When first column is frozen it is a child of tableView and requires extra bottom margin + horizontalFrameLayout.bottomMargin = tableView.isFirstColumnFrozen ? TableTheme.DefaultRowHeight : 0; horizontalFrameLayout.rightMargin = (int) PixelUtils.dpToPx(25); horizontalScrollView.setLayoutParams(horizontalFrameLayout); @@ -187,7 +186,9 @@ protected void createRecyclerViews() { coupledRecyclerView.setElevation(0); int headerHeight = tableView.headerHeight; - int marginTop = headerHeight + extraTopMargin; + int extraTop = tableView.totalsPosition.equals("top") ? tableView.totalsHeight : 0; + int extraBottom = tableView.totalsPosition.equals("bottom") ? tableView.totalsHeight : 0; + int marginTop = headerHeight + extraTop; linearLayout.recyclerView = coupledRecyclerView; coupledRecyclerView.setAdapter(dataProvider); @@ -200,7 +201,7 @@ protected void createRecyclerViews() { firstColumnRecyclerView.setAdapter(dataProvider); FrameLayout.LayoutParams firstColumnViewLayoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT); firstColumnViewLayoutParams.topMargin = marginTop; - firstColumnViewLayoutParams.bottomMargin = TableTheme.DefaultRowHeight; + firstColumnViewLayoutParams.bottomMargin = TableTheme.DefaultRowHeight + extraBottom; firstColumnRecyclerView.setLayoutParams(firstColumnViewLayoutParams); if(tableView.isFirstColumnFrozen) { @@ -298,15 +299,6 @@ protected void setupGrabbers() { void invalidateLayout() { if (this.coupledRecyclerView != null) { int width = dataColumns.get(0).width; - int marginTop = tableView.headerHeight + extraTopMargin; - - FrameLayout.LayoutParams recyclerViewLayoutParams = (FrameLayout.LayoutParams) coupledRecyclerView.getLayoutParams(); - recyclerViewLayoutParams.topMargin = marginTop; - coupledRecyclerView.setLayoutParams(recyclerViewLayoutParams); - - FrameLayout.LayoutParams firstColumnRecyclerViewLayoutParams = (FrameLayout.LayoutParams) firstColumnRecyclerView.getLayoutParams(); - firstColumnRecyclerViewLayoutParams.topMargin = marginTop; - firstColumnRecyclerView.setLayoutParams(firstColumnRecyclerViewLayoutParams); if (this.firstColumnHeaderCell != null) { ViewGroup.LayoutParams params = firstColumnHeaderCell.getLayoutParams(); @@ -327,15 +319,26 @@ void invalidateLayout() { this.headerView.updateLayout(); this.headerView.requestLayout(); + this.dataProvider.invalidateLayout(); - updateScrollbarBounds(); + int extraTop = tableView.totalsPosition.equals("top") ? tableView.totalsHeight : 0; + int extraBottom = tableView.totalsPosition.equals("bottom") ? tableView.totalsHeight : 0; + int marginTop = tableView.headerHeight + extraTop; + + FrameLayout.LayoutParams recyclerViewLayoutParams = (FrameLayout.LayoutParams) coupledRecyclerView.getLayoutParams(); + recyclerViewLayoutParams.topMargin = marginTop; + coupledRecyclerView.setLayoutParams(recyclerViewLayoutParams); - this.dataProvider.invalidateLayout(); if (this.firstColumnRecyclerView != null) { + FrameLayout.LayoutParams firstColumnRecyclerViewLayoutParams = (FrameLayout.LayoutParams) firstColumnRecyclerView.getLayoutParams(); + firstColumnRecyclerViewLayoutParams.topMargin = marginTop; + firstColumnRecyclerViewLayoutParams.bottomMargin = TableTheme.DefaultRowHeight + extraBottom; + firstColumnRecyclerView.setLayoutParams(firstColumnRecyclerViewLayoutParams); this.firstColumnRecyclerView.requestLayout(); } this.coupledRecyclerView.requestLayout(); + updateScrollbarBounds(); updateGrabbers(); this.rootLayout.requestLayout(); @@ -344,23 +347,7 @@ void invalidateLayout() { } private void createHeaderFactory() { - boolean topPosition = false; - if(this.totalsCells != null) { - switch(this.totalsPosition) { - case "bottom": - topPosition = false; - extraBottomMargin = tableView.totalsHeight; - break; - case "noTotals": - case "top": - default: - topPosition = true; - extraTopMargin = tableView.totalsHeight; - break; - } - - } - this.headerViewFactory = new HeaderViewFactory(dataColumns, totalsCells, dataProvider.totalsLabel, topPosition, tableView, tableView.headerContentStyle, context); + this.headerViewFactory = new HeaderViewFactory(dataColumns, totalsCells, dataProvider.totalsLabel, totalsPosition, tableView, tableView.headerContentStyle, context); } public void updateGrabbers() { @@ -399,7 +386,7 @@ public void updateHeaderViewLineCount() { if(headerViewFactory.topPosition && totalsView != null) { recyclerParams.topMargin += tableView.totalsHeight; - } else if(!headerViewFactory.topPosition && totalsView != null) { + } else if(headerViewFactory.bottomPosition && totalsView != null) { recyclerParams.bottomMargin = tableView.totalsHeight; } coupledRecyclerView.setLayoutParams(recyclerParams); @@ -430,9 +417,11 @@ public void updateFirstColumnsHeights() { if(firstColumnRecyclerView != null && tableView != null) { FrameLayout.LayoutParams dd = (FrameLayout.LayoutParams) firstColumnRecyclerView.getLayoutParams(); if(dd != null) { - dd.topMargin = tableView.headerHeight ; + dd.topMargin = tableView.headerHeight; if(headerViewFactory.topPosition && totalsView != null) { dd.topMargin += tableView.totalsHeight; + } else if(headerViewFactory.bottomPosition && totalsView != null) { + dd.bottomMargin = TableTheme.DefaultRowHeight + tableView.totalsHeight; } firstColumnRecyclerView.setLayoutParams(dd); updateFirstColumnHeaderHeight(); diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/TotalsView.java b/android/src/main/java/com/qliktrialreactnativestraighttable/TotalsView.java index 64e785c2..08c309d8 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/TotalsView.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/TotalsView.java @@ -2,7 +2,9 @@ import android.annotation.SuppressLint; import android.content.Context; +import android.view.Gravity; import android.view.ViewGroup; +import android.widget.LinearLayout; import android.widget.TextView; import java.util.List; @@ -50,6 +52,61 @@ public int getMaxLineCount() { TotalsViewCell totalsCell = (TotalsViewCell)this.getChildAt(i); totalsCell.setMaxLines(lineCount, dataColumns.get(i)); } + return lineCount; } + + public void updateTotals(List cols, DataProvider dataProvider) { + setDataColumns(cols); + // Create new totals when there are new columns + int totalCellCount = getChildCount(); + int numMissingCells = dataProvider.dataColumns.size() - totalCellCount; + int numCells = dataProvider.totalsCells.size(); + int j = numCells - numMissingCells; + for(int i = totalCellCount; i < dataProvider.dataColumns.size(); i++) { + DataColumn column = dataProvider.dataColumns.get(i); + TotalsViewCell totalsViewCell = HeaderViewFactory.createTotalsCell(getContext(), column, + tableView); + LinearLayout.LayoutParams totalsParams = new LinearLayout.LayoutParams(column.width, ViewGroup.LayoutParams.MATCH_PARENT); + if (!column.isDim && j < numCells) { + totalsViewCell.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL); + totalsViewCell.setText(dataProvider.totalsCells.get(j).qText); + j++; + } + addView(totalsViewCell, totalsParams); + } + // Update totals in case of moved columns + j = 0; + for(int i = 0; i < getChildCount(); i++) { + TotalsViewCell viewCell = (TotalsViewCell) getChildAt(i); + viewCell.setText(""); + + if(i > dataProvider.dataColumns.size() - 1) { + removeView(viewCell); + continue; + } + + DataColumn column = dataProvider.dataColumns.get(i); + viewCell.setColumn(column); + if(!column.isDim && j < dataProvider.totalsCells.size()) { + String newText = dataProvider.totalsCells.get(j).qText; + viewCell.setText(newText != null && newText.length() > 0 ? newText : ""); + j++; + } + } + + DataColumn firstColumn = dataProvider.dataColumns.get(0); + TotalsViewCell firstTotalsCell = (TotalsViewCell) getChildAt(0); + if(tableView.isFirstColumnFrozen) { + firstTotalsCell = tableView.tableViewFactory.firstColumnTotalsCell; + } + if (firstColumn.isDim) { + firstTotalsCell.setText(tableView.totalsLabel); + firstTotalsCell.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); + } else { + TotalsCell totalsCell = dataProvider.totalsCells.get(0); + firstTotalsCell.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL); + firstTotalsCell.setText(totalsCell.qText); + } + } } From a53e35049a828118febf5aacea5106e5468a0808 Mon Sep 17 00:00:00 2001 From: gruskal Date: Fri, 9 Dec 2022 13:04:23 -0500 Subject: [PATCH 2/4] fix: cleanup --- .../java/com/qliktrialreactnativestraighttable/TableView.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/TableView.java b/android/src/main/java/com/qliktrialreactnativestraighttable/TableView.java index b0811ac3..8aec1fec 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/TableView.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/TableView.java @@ -190,10 +190,6 @@ public void setDataColumns(List cols) { tableViewFactory.firstColumnHeaderCell.setColumn(cols.get(0)); } - if(tableViewFactory.firstColumnTotalsCell != null) { - tableViewFactory.firstColumnTotalsCell.setText(totalsLabel); - } - if(grabbers != null) { for(GrabberView grabberView : grabbers) { grabberView.setDataProvider(dataProvider); From 1385c6fac6a365e9142d97c799281774a6190738 Mon Sep 17 00:00:00 2001 From: gruskal Date: Fri, 9 Dec 2022 14:39:16 -0500 Subject: [PATCH 3/4] fix: address comments --- .../DataProvider.java | 5 +- .../HeaderViewFactory.java | 2 +- .../ReactNativeStraightTableViewManager.java | 1 + .../TableView.java | 24 ++++++-- .../TableViewFactory.java | 61 +++++++++---------- 5 files changed, 54 insertions(+), 39 deletions(-) diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/DataProvider.java b/android/src/main/java/com/qliktrialreactnativestraighttable/DataProvider.java index 256c0cb2..751bb378 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/DataProvider.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/DataProvider.java @@ -69,13 +69,16 @@ public void setLoading(boolean loading) { public void setTotals(ReadableArray totals, String totalsLabel, String totalsPosition) { if(this.isDataView) { + this.totalsCells = null; + this.totalsLabel = null; this.totalsPosition = "noTotals"; + return; } + if(totals != null) { this.totalsCells = HeaderViewFactory.getTotalsCellList(totals); this.totalsLabel = totalsLabel; } - this.totalsPosition = totalsPosition == null ? "noTotals" : totalsPosition; } public void setFirstColumnFrozen(boolean firstColumnFrozen) { diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/HeaderViewFactory.java b/android/src/main/java/com/qliktrialreactnativestraighttable/HeaderViewFactory.java index 9e04694e..7f6a601e 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/HeaderViewFactory.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/HeaderViewFactory.java @@ -55,7 +55,7 @@ public HeaderViewFactory(List dataColumns, List totalsCe this.bottomPosition = totalsPosition.equals("bottom"); this.headerContentStyle = contentStyle; buildHeader(context); - if (totalsCells != null && !totalsPosition.equals("noTotals")) { + if (totalsCells != null) { buildTotals(context); } } diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/ReactNativeStraightTableViewManager.java b/android/src/main/java/com/qliktrialreactnativestraighttable/ReactNativeStraightTableViewManager.java index 3ed34320..69f0c5eb 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/ReactNativeStraightTableViewManager.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/ReactNativeStraightTableViewManager.java @@ -65,6 +65,7 @@ private List processColumns(TableView tableView, ReadableMap cols) { totalsPosition = totals.getString("position"); totalsLabel = totals.getString("label"); totalsRows = totals.getArray("rows"); + tableView.setTotals(totalsRows, totalsPosition, totalsLabel); } diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/TableView.java b/android/src/main/java/com/qliktrialreactnativestraighttable/TableView.java index 8aec1fec..900d9f69 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/TableView.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/TableView.java @@ -91,8 +91,23 @@ public int getContentBottom() { public void setTotals(ReadableArray totalsRows, String totalsPosition, String totalsLabel) { this.totalsLabel = totalsLabel; this.totalsRows = totalsRows; - this.totalsPosition = totalsPosition; - dataProvider.setTotals(totalsRows, totalsLabel, totalsPosition); + + if(totalsPosition == null) { + this.totalsPosition = "noTotals"; + } else { + switch(totalsPosition) { + case "bottom": + this.totalsPosition = totalsPosition; + break; + default: + case "noTotals": + case "top": + this.totalsPosition = "top"; + break; + } + } + + dataProvider.setTotals(totalsRows, totalsLabel, this.totalsPosition); } public void clearSelections() { @@ -270,7 +285,7 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { } void createRecyclerView() { - dataProvider.setTotals(totalsRows, totalsLabel, totalsPosition); + setTotals(totalsRows, totalsPosition, totalsLabel); tableViewFactory.createAll(); recyclerView = tableViewFactory.coupledRecyclerView; grabbers = tableViewFactory.grabbers; @@ -280,9 +295,6 @@ void createRecyclerView() { verticalScrollBar = tableViewFactory.verticalScrollBar; screenGuideView = tableViewFactory.screenGuideView; firstColumnView = tableViewFactory.firstColumnRecyclerView; - post(() -> { - tableViewFactory.updateScrollbarBounds(); - }); } void invalidateLayout() { diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/TableViewFactory.java b/android/src/main/java/com/qliktrialreactnativestraighttable/TableViewFactory.java index 8709c29f..df0ca2cf 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/TableViewFactory.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/TableViewFactory.java @@ -89,6 +89,8 @@ public void createAll() { @Override public void run() { updateGrabbers(); + updateScrollbarBounds(); + updateRecyclerViewMargins(); } }); } @@ -178,30 +180,21 @@ protected void createTotalsView() { protected void createRecyclerViews() { CustomLinearLayoutManger linearLayout = new CustomLinearLayoutManger(context); + linearLayout.recyclerView = coupledRecyclerView; + coupledRecyclerView = new CustomRecyclerView(context, false, dataProvider, tableView, linearLayout, dragBox, firstColumnDragBox); FrameLayout.LayoutParams recyclerViewLayoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); - CustomLinearLayoutManger firstColumnLinearLayout = new CustomLinearLayoutManger(context); - firstColumnRecyclerView = new CustomRecyclerView(context, true, dataProvider, tableView, firstColumnLinearLayout, dragBox, firstColumnDragBox); + coupledRecyclerView.setLayoutParams(recyclerViewLayoutParams); coupledRecyclerView.setZ(0); coupledRecyclerView.setElevation(0); - - int headerHeight = tableView.headerHeight; - int extraTop = tableView.totalsPosition.equals("top") ? tableView.totalsHeight : 0; - int extraBottom = tableView.totalsPosition.equals("bottom") ? tableView.totalsHeight : 0; - int marginTop = headerHeight + extraTop; - - linearLayout.recyclerView = coupledRecyclerView; coupledRecyclerView.setAdapter(dataProvider); - - recyclerViewLayoutParams.topMargin = marginTop; - coupledRecyclerView.setLayoutParams(recyclerViewLayoutParams); rootLayout.addView(coupledRecyclerView, recyclerViewLayoutParams); + CustomLinearLayoutManger firstColumnLinearLayout = new CustomLinearLayoutManger(context); + firstColumnRecyclerView = new CustomRecyclerView(context, true, dataProvider, tableView, firstColumnLinearLayout, dragBox, firstColumnDragBox); firstColumnLinearLayout.recyclerView = firstColumnRecyclerView; firstColumnRecyclerView.setAdapter(dataProvider); FrameLayout.LayoutParams firstColumnViewLayoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT); - firstColumnViewLayoutParams.topMargin = marginTop; - firstColumnViewLayoutParams.bottomMargin = TableTheme.DefaultRowHeight + extraBottom; firstColumnRecyclerView.setLayoutParams(firstColumnViewLayoutParams); if(tableView.isFirstColumnFrozen) { @@ -321,22 +314,7 @@ void invalidateLayout() { this.headerView.requestLayout(); this.dataProvider.invalidateLayout(); - int extraTop = tableView.totalsPosition.equals("top") ? tableView.totalsHeight : 0; - int extraBottom = tableView.totalsPosition.equals("bottom") ? tableView.totalsHeight : 0; - int marginTop = tableView.headerHeight + extraTop; - - FrameLayout.LayoutParams recyclerViewLayoutParams = (FrameLayout.LayoutParams) coupledRecyclerView.getLayoutParams(); - recyclerViewLayoutParams.topMargin = marginTop; - coupledRecyclerView.setLayoutParams(recyclerViewLayoutParams); - - if (this.firstColumnRecyclerView != null) { - FrameLayout.LayoutParams firstColumnRecyclerViewLayoutParams = (FrameLayout.LayoutParams) firstColumnRecyclerView.getLayoutParams(); - firstColumnRecyclerViewLayoutParams.topMargin = marginTop; - firstColumnRecyclerViewLayoutParams.bottomMargin = TableTheme.DefaultRowHeight + extraBottom; - firstColumnRecyclerView.setLayoutParams(firstColumnRecyclerViewLayoutParams); - this.firstColumnRecyclerView.requestLayout(); - } - this.coupledRecyclerView.requestLayout(); + updateRecyclerViewMargins(); updateScrollbarBounds(); updateGrabbers(); @@ -347,7 +325,28 @@ void invalidateLayout() { } private void createHeaderFactory() { - this.headerViewFactory = new HeaderViewFactory(dataColumns, totalsCells, dataProvider.totalsLabel, totalsPosition, tableView, tableView.headerContentStyle, context); + this.headerViewFactory = new HeaderViewFactory(dataColumns, totalsCells, dataProvider.totalsLabel, tableView.totalsPosition, tableView, tableView.headerContentStyle, context); + } + + private void updateRecyclerViewMargins() { + int extraTop = tableView.totalsPosition.equals("top") ? tableView.totalsHeight : 0; + int extraBottom = tableView.totalsPosition.equals("bottom") ? tableView.totalsHeight : 0; + int marginTop = tableView.headerHeight + extraTop; + + FrameLayout.LayoutParams recyclerViewLayoutParams = (FrameLayout.LayoutParams) coupledRecyclerView.getLayoutParams(); + recyclerViewLayoutParams.topMargin = marginTop; + recyclerViewLayoutParams.bottomMargin = extraBottom; + + coupledRecyclerView.setLayoutParams(recyclerViewLayoutParams); + + if (this.firstColumnRecyclerView != null) { + FrameLayout.LayoutParams firstColumnRecyclerViewLayoutParams = (FrameLayout.LayoutParams) firstColumnRecyclerView.getLayoutParams(); + firstColumnRecyclerViewLayoutParams.topMargin = marginTop; + firstColumnRecyclerViewLayoutParams.bottomMargin = TableTheme.DefaultRowHeight + extraBottom; + firstColumnRecyclerView.setLayoutParams(firstColumnRecyclerViewLayoutParams); + this.firstColumnRecyclerView.requestLayout(); + } + this.coupledRecyclerView.requestLayout(); } public void updateGrabbers() { From 10fbd3463623469e390f1c2e66f6b572f77fe308 Mon Sep 17 00:00:00 2001 From: gruskal Date: Fri, 9 Dec 2022 14:43:04 -0500 Subject: [PATCH 4/4] fix: cleanup --- .../qliktrialreactnativestraighttable/TableViewFactory.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/TableViewFactory.java b/android/src/main/java/com/qliktrialreactnativestraighttable/TableViewFactory.java index df0ca2cf..83f6cd4a 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/TableViewFactory.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/TableViewFactory.java @@ -114,8 +114,7 @@ private void setMockScrollLayouts() { FrameLayout.LayoutParams horizontalFrameLayout = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, (int) PixelUtils.dpToPx(5)); horizontalFrameLayout.gravity = Gravity.BOTTOM; - // When first column is frozen it is a child of tableView and requires extra bottom margin - horizontalFrameLayout.bottomMargin = tableView.isFirstColumnFrozen ? TableTheme.DefaultRowHeight : 0; + horizontalFrameLayout.bottomMargin = TableTheme.DefaultRowHeight; horizontalFrameLayout.rightMargin = (int) PixelUtils.dpToPx(25); horizontalScrollView.setLayoutParams(horizontalFrameLayout);