Skip to content

Commit 81c99a8

Browse files
committed
fixed The correct context being passed to createView
Should of fixed #135, #120.
1 parent 5a11cd5 commit 81c99a8

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/CalligraphyLayoutInflater.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,15 @@ protected View onCreateView(String name, AttributeSet attrs) throws ClassNotFoun
175175
* will fall back through to the PhoneLayoutInflater method of inflating custom views where
176176
* Calligraphy will NOT have a hook into.
177177
*
178-
* @param parent parent view
179-
* @param view view if it has been inflated by this point, if this is not null this method
180-
* just returns this value.
181-
* @param name name of the thing to inflate.
182-
* @param context Context to inflate by if parent is null
183-
* @param attrs Attr for this view which we can steal fontPath from too.
178+
* @param parent parent view
179+
* @param view view if it has been inflated by this point, if this is not null this method
180+
* just returns this value.
181+
* @param name name of the thing to inflate.
182+
* @param viewContext Context to inflate by if parent is null
183+
* @param attrs Attr for this view which we can steal fontPath from too.
184184
* @return view or the View we inflate in here.
185185
*/
186-
private View createCustomViewInternal(View parent, View view, String name, Context context, AttributeSet attrs) {
186+
private View createCustomViewInternal(View parent, View view, String name, Context viewContext, AttributeSet attrs) {
187187
// I by no means advise anyone to do this normally, but Google have locked down access to
188188
// the createView() method, so we never get a callback with attributes at the end of the
189189
// createViewFromTag chain (which would solve all this unnecessary rubbish).
@@ -200,7 +200,10 @@ private View createCustomViewInternal(View parent, View view, String name, Conte
200200

201201
final Object[] mConstructorArgsArr = (Object[]) ReflectionUtils.getValue(mConstructorArgs, this);
202202
final Object lastContext = mConstructorArgsArr[0];
203-
mConstructorArgsArr[0] = parent != null ? parent.getContext() : context;
203+
// The LayoutInflater actually finds out the correct context to use. We just need to set
204+
// it on the mConstructor for the internal method.
205+
// Set the constructor ars up for the createView, not sure why we can't pass these in.
206+
mConstructorArgsArr[0] = viewContext;
204207
ReflectionUtils.setValue(mConstructorArgs, this, mConstructorArgsArr);
205208
try {
206209
view = createView(name, null, attrs);

0 commit comments

Comments
 (0)